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?
1 Answer
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
\read7 to \@Data
\ifeof7\else
\sbox\pst@hbox{\@Data}
\ifdim\wd\pst@hbox=0\p@
\immediate\closeout\pst@out
\advance\psLoopIndex by 1
\immediate\openout\pst@out=#2\the\psLoopIndex
\else
\immediate\write\pst@out{\@Data}%
\fi
\repeat
\closein7
\closeout\pst@out
\advance\psLoopIndex by -1
}
\makeatother
\begin{document}
\saveDataAsFiles{demo0.data}{Data}
\psset{xunit=2}
\begin{pspicture}[showgrid](3,10)
\psforeach{\iA}{0,1,2}{% {0,1,..,82}
\readdata\myData{Data\iA.tex}%
\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
\read7 to \@Data
\ifeof7\else
\sbox\pst@hbox{\@Data}
\ifdim\wd\pst@hbox=0\p@
\advance\psLoopIndex by 1
\@namedef{#2\the\psLoopIndex}{}
\else
\edef\@temp{\@nameuse{#2\the\psLoopIndex} \@Data}
\expandafter\let\csname#2\the\psLoopIndex\endcsname\@temp
\fi
\repeat
\closein7
\advance\psLoopIndex by -1
}
\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}
nStart=..
andnEnd=..
. See documentation of `pst-plot? pp66