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

I have recently discovered the wonderful pgfplots package and I've started coding my Python code to output tabular data of whatever is plotted (at least for simple plots). In my LaTeX source code, I use plot file {../datafiles/data.dat}; and similar commands extensively. All my external figures (yes, I still have some) are in a separate directory that I specify in my preamble using \graphicspath{...}. Is there any equivalent path that TikZ and pgfplots use to search for data files?

I have difficulties searching for an answer to this question, because the word path has such a specific meaning in a TikZ context. I'm using PGF 2.10 and pgfplots 1.5. I checked in the PGF manual (section 19.4, page 224) and in the pgfplots manual (section 4.2.2, page 25–26) but did not find anything relevant.

MWE:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot plot file {somedata.dat};
\end{axis}
\end{tikzpicture}
\end{document}

where somedata.dat contains:

1 2
3 4
5 6
7 8
9 10

Sorry for not adding a MWE earlier, I figured it wasn't needed because the question was obvious.

share|improve this question
2  
Note that "software support" for search paths in TeX is only one possible approach. An alternative is to set the TeX search path BEFORE calling TeX: its search path is applied to any graphics and data files as well. Consequently, you could configure your Python scripts to modify the TEXINPUTS environment variable, and all would work out-of-the-box. For linux, this is extremely simple - I am not so sure if that works for MikTeX under Windows as well (but I suppose the general idea will work). – Christian Feuersänger Nov 26 '11 at 22:28
    
To extend Christian's comment until pgfplots can do this natively TEXINPUTS can contain even relative paths and LaTeX searchs recursively. So a simple environment variable setting such as TEXINPUTS=.// will tell LaTeX to search the current directory and all subdirectories. This might slow the compilation down a bit for a large number of files/directories but I did not experience a big effect. – Alexander Nov 12 '12 at 17:31
up vote 3 down vote accepted

This feature has been added to the PGFPlots v1.13 with the key table/search path which works for \addplot table {<file>}; (as the key name suggests). It can be found in the manual in section 4.3.2 on page 52.

\begin{filecontents*}{plots/data/somedata.dat}
1 2
3 4
5 6
7 8
9 10
\end{filecontents*}
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
    \pgfplotsset{
        table/search path={plots/data},
    }
\begin{document}
    \begin{tikzpicture}
        \begin{axis}
            \addplot table {somedata.dat};
        \end{axis}
    \end{tikzpicture}
\end{document}

image of the above shown code

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.