4

How do I plot with pst-plot when the x- and y- data are stored in different files?

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{pst-plot}
\usepackage{auto-pst-pdf}

\begin{document}

\begin{postscript}
\readdata{\xData}{x.dat}
\readdata{\yData}{y.dat}
\begin{psgraph}[axesstyle=frame](0,0)(25,7.5){10cm}{6cm}
\listplot{**What to do here?**}
\end{psgraph}
\end{postscript}

\end{document}
5

Inside PostScript you can do anything:

\readdata{\xData}{x.dat}
\readdata{\yData}{y.dat}
\def\DATA{ 
  /X [\xData] def /Y [\yData] def % save as array
  0 1 X length 1 sub {            % on stack is the loop variable
    /Index ED                     % save it 
    X Index get Y Index get       % get x y
  } for }                         % end for loop
\begin{psgraph}[axesstyle=frame,Dx=2](0,0)(25,7.5){10cm}{6cm}
\listplot{\DATA}
\end{psgraph}
| improve this answer | |
  • Dear Herbert, since I don't know how to contact you otherwise, I believe that there is a bug in the pst-plot manual. The command \psreadColumnData described on p. 5 probably should read \psreadDataColumn. +1 for the nice answer. – user121799 Feb 14 '18 at 1:52
4

Here's how you would do this with PGFPlots. You can make a column from a different table available using the copy column from table style.

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots, pgfplotstable}
\usepackage{filecontents}

\begin{filecontents}{A.dat}
0
1
2
3
4
5
\end{filecontents}

\begin{filecontents}{B.dat}
0
1
4
9
16
25
\end{filecontents}

\pgfplotstableset{
create on use/y/.style={create col/copy column from table={B.dat}{0}}
}

\begin{document}

\begin{tikzpicture}
\begin{axis}
\addplot table [y=y] {x.dat};
\end{axis}
\end{tikzpicture}

\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.