# plot many polylines

I want to plot 82 polylines using pstricks. Do I really have to put every polyline into its own file and use 82 \fileplot-statements or is there a way to put them alltogether in one file and plot them all?

• You can use nStart=.. and nEnd=... See documentation of pst-plot? pp66 – user2478 Dec 12 '17 at 19:36
• The problem is that the polylines don't have equally many coordinates. The best would be if I could use a delimiter (e.g. a blanc line) in the data-file. – user2033412 Dec 12 '17 at 19:57

Put an empty line in the the data file where a new sequence starts.

\saveDataAsFiles{demo.data}{Data}


demo.data is the existing data file with the empty line as separator and Data is the prefix for the created files Data0.tex, Data1.tex,...

\documentclass[a4paper]{article}
\usepackage{pst-plot}
\makeatletter
\newwrite\pst@out
\def\saveDataAsFiles#1#2{%  Filename Prefix
\psLoopIndex=0\relax
\immediate\openin7=#1
\immediate\openout\pst@out=#2\the\psLoopIndex
\loop
\ifeof7\else
\sbox\pst@hbox{\@Data}
\ifdim\wd\pst@hbox=0\p@
\immediate\closeout\pst@out
\immediate\openout\pst@out=#2\the\psLoopIndex
\else
\immediate\write\pst@out{\@Data}%
\fi
\repeat
\closein7
\closeout\pst@out
}
\makeatother
\begin{document}

\saveDataAsFiles{demo0.data}{Data}

\psset{xunit=2}
\begin{pspicture}[showgrid](3,10)
\psforeach{\iA}{0,1,2}{%   {0,1,..,82}
\listplot[showpoints]{\myData}%
}
\end{pspicture}
\end{document}


and the same which saves the data into macros \Data0, \Data1,...

\documentclass[a4paper]{article}
\usepackage{pst-plot}
\makeatletter
\def\saveDataAsMacro#1#2{%  Filename Prefix
%  \newlinechar\^^J"
\psLoopIndex=0\relax
\immediate\openin7=#1
\@namedef{#2\the\psLoopIndex}{}
\loop
\ifeof7\else
\sbox\pst@hbox{\@Data}
\ifdim\wd\pst@hbox=0\p@
\@namedef{#2\the\psLoopIndex}{}
\else
\edef\@temp{\@nameuse{#2\the\psLoopIndex} \@Data}
\expandafter\let\csname#2\the\psLoopIndex\endcsname\@temp
\fi
\repeat
\closein7
}
\makeatother
\begin{document}

\saveDataAsMacro{demo0.data}{Data}

\psset{xunit=2}
\begin{pspicture}[showgrid](3,10)
\multido{\iA=0+1}{82}{%
\listplot[showpoints]{\csname Data\iA\endcsname}%
}
\end{pspicture}
\end{document}

• This is madness. I love it! :-) – user2033412 Dec 12 '17 at 21:24
• Version #2 is even better -- no temporary files! – user2033412 Dec 12 '17 at 21:43