pgfplots from file: search path, looking for \graphicspath equivalent

8,921

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:
8,921

Related videos on Youtube

gerrit
Author by

gerrit

Updated on January 10, 2020

Comments

  • gerrit
    gerrit almost 3 years

    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.

    • Christian Feuersänger
      Christian Feuersänger almost 11 years
      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).
    • Alexander
      Alexander about 10 years
      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.