1

The Tikz command \draw plot file{data/filename.dat} draws a line through the coordinates stored in filename.dat, which is contained in the subfolder data. Is there a Tikz equivalent to \graphicspath{{./data/}} so that I don't have to write data/ in front of every plot command?

This post shows how to it with the pgfplots package, but I'm wondering if there is a Tikz native way for the same feature. I don't really want to load the entire pgfplots package just to avoid typing data/.

Here is an MWE:

\begin{filecontents*}{data/somedata.dat}
1 2
3 4
5 6
\end{filecontents*}

\documentclass{standalone} \usepackage{tikz, graphicx} \graphicspath{{./data/}}

\begin{document} \begin{tikzpicture} \draw plot file{somedata.dat}; \end{tikzpicture} \end{document}

1 Answers1

1

It turns out \tikzset{every plot/.style={prefix=data/}} only applies to plots that are generated with GNUplot through the plot function operation. To apply the prefix to plots from data points in a file, one can add the following code to the preamble.

\makeatletter
\def\tikz@plot@file ile#1{\def\tikz@plot@data{\pgfplotxyfile{\tikz@plot@prefix#1}}\tikz@@@plot}
\makeatother
\tikzset{every plot/.style={prefix=data/}}

This really just adds the plot/prefix key, which is stored in \tikz@plot@prefix, to the file name that is passed to plot file. There are probably better ways to patch this because this will break if the plot file operation is ever reimplemented. But for now it works.