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.

Is it possible to draw a graph with pgfplots using data from different files ?

Let say I have two data files : data.dat and error.dat and would like to plot column 1 versus column 0 from data.dat and add error bars from error.dat.

If the data all came from the same file all.dat, I would use :

\pgfplotstableread{./all.dat}\mytable

\addplot  table[x index=0,y index=1, y error index=3]{\mytable};
share|improve this question

1 Answer 1

up vote 10 down vote accepted

It is possible. You can make a column from a different table available on the fly using

\pgfplotstableset{
    create on use/<new column name>/.style={
        create col/copy column from table={<file or table>}{<column name>}
    }
}

So, to get something like

you could do something like

\documentclass{article} 
\usepackage{filecontents}
\begin{filecontents}{data.dat}
X   Y
1   3
2   7
3   4
4   5
5   5
6   9
\end{filecontents}

\begin{filecontents}{error.dat}
Errors
1
3
2
2.5
3
1
\end{filecontents}

\usepackage{pgfplots,pgfplotstable}

\pgfplotstableread{data.dat}\datatable

\pgfplotstableset{
    create on use/errors/.style={
        create col/copy column from table={error.dat}{Errors}
    }
}


\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=0,ymin=0]
\addplot +[
    black,
    error bars/.cd,
        y explicit,
        y dir=both
    ] table [y error=errors] {\datatable};
\end{axis}
\end{tikzpicture}

\end{document}
share|improve this answer

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.