Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have two data files (xxxx.txt and yyyy.txt), each only containing one column of x and y data respectively. Now I want to plot these two data together in a simple 2D diagram. Has anybody an idea how this is possible?

Until now I always had my x and y data in one file together (two columns, first x, second y). So there was no problem and I plotted my data like:

\begin{tikzpicture}
\begin{axis}
   \addplot table {datatable.txt};
\end{axis}
\end{tikzpicture}

Does anybody have a helpful idea or solution?

share|improve this question
add comment

1 Answer

up vote 12 down vote accepted

Yes, pgfplotstable allows you to define something like "virtual columns", which are created once you try to access them (either in an \addplot table command or using \pgfplotstabletypeset for example), which can acquire data in a variety of ways. One of the creation methods for these virtual columns is copy column from table={<table or file name>}{<column name>}.

If you set

\pgfplotstableset{
    create on use/Y/.style={create col/copy column from table={dataB.txt}{0}}
}

then whenever you try to access column Y (of whatever table), the data from dataB.txt will be used:

\documentclass{article}
\usepackage{pgfplots, pgfplotstable}
\usepackage{filecontents}
\begin{filecontents}{dataA.txt}
2
3
4
5
3
5
\end{filecontents}
\begin{filecontents}{dataB.txt}
5
4
3
2
5
5
\end{filecontents}

\pgfplotstableset{
    create on use/Y/.style={create col/copy column from table={dataB.txt}{0}}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot table [y=Y] {dataA.txt};
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
thank you, perfect –  David K. Jun 22 '12 at 18:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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