3

I'm plotting a line from a file with pstricks using the following code:

\begin{pspicture}(0,0)(10,10)
    \saveDataAsNodes{some-file.data}{N}
    \psncurve{->}(0,6){N}
    \cnodeput(N0){A}{A}
    \cnodeput(N6){B}{B}
\end{pspicture}

The points at the beginning and the end should be labeled with A and B respectively.

With my current code I always have to adapt two positions in the code to match the number of points in the file (7 in this case, hence \psncurve{->}(0,6){N} and \cnodeput(N6){B}{B}).

Is there any way to adapt the graphic automatically to the number of points in the file?

4

With the pst-node.tex from http://archiv.dante.de/~herbert/texnik/tex/generic/pst-node/ you can use the node #1Last:

\documentclass[a4paper]{article}    
\usepackage{pstricks-add}
\begin{document}
    \begin{pspicture}[showgrid](6.5,6.5)(16,16)
    \saveDataAsNodes{node2.dat}{N}
    \psncurve{->}(0,\the\psLoopIndex){N}
    \cnodeput(N0){A}{A}
    \cnodeput(NLast){B}{B}
    \end{pspicture}
\end{document}

enter image description here

|improve this answer|||||
  • Do you have any plans to move this into the official repositories, Herbert? – user2033412 Dec 9 '17 at 21:35
  • It is already on CTAN and should be available with texlive or miktex in the update – user2478 Dec 10 '17 at 5:54
4

I guess you want \psLoopIndex from p. 41 of the pstricks documentation.

\documentclass[a4paper]{article}
\usepackage{filecontents} % from https://tex.stackexchange.com/questions/194752/plotting-a-directed-graph-using-pgfplots/194806#194806
\begin{filecontents*}{node2.dat}
12  12
12  13
13  15
15  15
15  13
13  12
12  10
10  8
8   8
8   10
10  12
12  12
12  10
10  10
\end{filecontents*}
\usepackage{pst-node,pst-plot}
\begin{document}
\begin{pspicture}(6.5,6.5)(16,16)
    \saveDataAsNodes{node2.dat}{N}
    \newcount\iB
    \iB=\numexpr\the\psLoopIndex-1\relax % from the pstricks documentation
    \typeout{read \the\iB coordinates}
    \psncurve{->}(0,\the\iB){N}
    \cnodeput(N0){A}{A}
    \cnodeput(N\the\iB){B}{B}
\end{pspicture}
\end{document}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.