# Plot x y data from different files/tables

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}
\end{axis}
\end{tikzpicture}


Does anybody have a helpful idea or solution?

-

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}