3

I would like to store data for a pgfplot inside my source file, without creating an extra file. However, there seems to be a difference between loading the data from an external file (provided here via filecontents) and storing it in a macro using pgfplotstableread.

The code below runs when data.dat is loaded by the addplots, and causes errors when the second file name (see comment in the source code) is replaced by the table macro \data.

\documentclass{article} 
\usepackage{siunitx}
\usepackage{pgfplots}\pgfplotsset{compat=1.14, small}
\usepackage{pgfplotstable}

\begin{filecontents*}{data.dat}
x   error   y   label
-0.3294 0.0012  -1  \num{-0.329(2)}
-0.3296 0.0012  -2  -0.330(2)
\end{filecontents*}

\pgfplotstableread{
x   error   y   label
-0.3294 0.0012  -1  \num{-0.329(2)}
-0.3296 0.0012  -2  -0.330(2)
}{\data}

\begin{document}
\begin{tikzpicture}
\begin{axis}[xmax=-0.293,
    visualization depends on={value \thisrow{label} \as \labela},
    nodes near coords align={horizontal}]
\addplot+[only marks, error bars/.cd, x dir=both, x explicit] 
    table[x=x,y=y,x error=error] {\data};
\addplot [nodes near coords={\labela}, only marks, mark=none] 
    table[x expr=\pgfkeysvalueof{/pgfplots/xmax}, y=y] {data.dat};  % replacing data.dat with \data results in errors
\end{axis}
\end{tikzpicture}
\end{document}

Is there a way to achieve the same result in both cases? Any help is appreciated.

3
  • 1
    You encountered the already known bug again which is already reported at sourceforge.net/p/pgfplots/bugs/109. Commented Oct 11, 2017 at 11:46
  • So it has to do with visualization depends on rather than the content of that specific column.
    – FlorianL
    Commented Oct 11, 2017 at 12:00
  • That is what the bug report states, yes. Commented Oct 11, 2017 at 12:04

1 Answer 1

1

After the bug had been filed by @Stefan Pinnow, I found that problems with \pgfplotstableread also occur for matrix plots. So there is not only an issue with visualization depends on.

Here is an example:

\documentclass{article} 
\usepackage{pgfplots}
    \pgfplotsset{compat=1.14, small, scale only axis}

\begin{filecontents*}{data.dat}
x   y   Val
1   1   1
2   1   0
1   2   0
2   2   1
\end{filecontents*}

\pgfplotstableread{
x   y   Val
1   1   1
2   1   0
1   2   0
2   2   1
}{\data}

\begin{document}

\begin{tikzpicture} 
\begin{axis}[width=2cm, height=2cm, enlargelimits=false, title=filecontents]
    \addplot[matrix plot, mesh/cols=2, point meta=explicit]
        table[meta=Val] {data.dat};
\end{axis}

\begin{axis}[xshift=4cm, width=2cm, height=2cm, enlargelimits=false, title=pgfplotstableread]
    \addplot[matrix plot, mesh/cols=2, point meta=explicit]
        table[meta=Val] {\data};
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .