2

I use pgfplots for the first time, so the error is probably at my end, but I was under the impression that xlabels from data={\table}{colname} could be used to set strings from a data table as x-labels. However, when I try it, it does nothing at all, the labels are still numbers (maybe it has to do with x expr=\coordindex, but that is also not what is printed).

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{filecontents}

\begin{filecontents}{data.dat}
   fname foo
   one     1
   two     2
   three   3
\end{filecontents}

\begin{document}
\pgfplotstableread[col sep=space]{data.dat}\datatable
\begin{tikzpicture}
   \begin{axis}[
         xlabel={Image Number},
         ylabel={Distance ratio}
      ]
      \addplot table[
         xticklabels from table={\datatable}{fname},
         x expr=\coordindex,
         y=foo,
      ] {\datatable};
   \end{axis}
\end{tikzpicture}
\end{document}

The result: enter image description here

How do I correctly use the key /pgfplots/xticklabels from table?

1 Answer 1

5

This should fix your problem:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{filecontents}

\begin{filecontents}{data.dat}
   fname foo
   one     1
   two     2
   three   3
\end{filecontents}

\begin{document}
\pgfplotstableread[col sep=space]{data.dat}\datatable
\begin{tikzpicture}
   \begin{axis}[
         xlabel={Image Number},
         xticklabels from table={data.dat}{fname},
         xtick=data,
         ylabel={Distance ratio}
      ]
      \addplot table[
         x expr=\coordindex,
         y=foo,         
      ] {\datatable};
   \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Have a loot at this post for some details.

1
  • Indeed it does, I just found the same.
    – oarfish
    Aug 21, 2015 at 10:11

You must log in to answer this question.

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