# Plotting one column of data in PGF

I have a 1-column file which I load, it has a single column named "q":

\pgfplotstableread{qq.csv}\RecoveryQQN


The file contains data like:

q
0.000
0.001


I can plot with x expr:

\begin{tikzpicture}
\begin{axis}[
xlabel={Theoretical Quantile},
ylabel={Data Quantile}
]
\addplot table [x expr=\coordindex, y=q] from \RecoveryQQN;
\end{axis}
\end{tikzpicture}


This produces the expected result. But if I swap X and Y:

\addplot table [x=q, y expr=\coordindex] from \RecoveryQQN;


I get the following error message:

Package pgfplots Error: The requested list entry with
index 1 of \RecoveryQQN is too large; this list has
not enough elements..

See the pgfplots package documentation for explanation.
Type  H   for immediate help.


How can I display the plot with the X and Y axes flipped?

Welcome to TeX-SE! If you plot the data without the detour, i.e. without loading the table into a macro and then feeding the macro into the plot, it works as expected. For the future, please consider providing a complete code like the following one.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{filecontents}
\begin{filecontents*}{qq.csv}
q
0.000
0.001
\end{filecontents*}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel={Theoretical Quantile},
ylabel={Data Quantile}
]
\addplot table [x=q, y expr=\coordindex]  {qq.csv};
\end{axis}
\end{tikzpicture}
\end{document}


• This lets me write the document, but what is the reason why loading a table into a macro would have an effect here? May 1 '19 at 21:18
• @DietrichEpp I really do not know why this is, but it is known that there is an asymmetry in how tables that get stored in macros are treated vs. tables that are directly fed into the plots, see e.g. tex.stackexchange.com/a/356790/121799. Sometimes one has to use workarounds but I am not aware of a universal way to remove the asymmetry. I think that it is because pgfplotstable throws away information when loading the table in a macro.
– user121799
May 1 '19 at 21:44
• All the tables shown in the pgf[plotstable manual have a column of index numbers. In fact, some operations require a column of index numbers. It is, however, possible to create one post hoc. May 2 '19 at 3:35