绘制多条折线

绘制多条折线

我想使用 pstricks 绘制 82 条折线。我真的必须将每条折线放入其自己的文件中并使用 82 个 \fileplot 语句吗?或者有没有办法将它们全部放在一个文件中并绘制它们?

答案1

在数据文件中新序列开始的位置放置一个空行。

\saveDataAsFiles{demo.data}{Data}

demo.data是以空行作为分隔符的现有数据文件, Data是所创建文件的前缀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}

并将数据保存到宏中\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}

相关内容