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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

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

marked as duplicate by Fran, R. Schumacher, Stefan Pinnow, Papiro, Jesse Jun 18 at 12:54

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 13 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

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