2

I'm using pgfplots to plot experimental data and there are currently way too many marks on the x-axis.

In the documentation I found the xtick distance-command, but LaTeX gives this error message:

I do not know the key '/tikz/xtick distance'

What am I doing wrong?

% Preamble
\usepackage{pgfplots}
\pgfplotsset{compat=1.5, width=0.7\linewidth}

% Code
\begin{tikzpicture}
  \begin{axis}[
    xtick distance=10,   
    xlabel={Magnetic field [\si{G}]},
    ylabel={EPR-Signal [\si{a.u.}]},
    xmin=3390, xmax=3460,
  ]

    \addplot[black] table {...};
    \addplot[red] table {...};

    \legend{Experiment,Simulation}

  \end{axis}
\end{tikzpicture}
  • 1
    I would guess that the version of pgfplots you have installed doesn't correspond to the version of the documentation you're reading, your example works fine here, with version 1.14 (the latest version). \pgfplotsversion will print the version number, so you can add that to your document to see which version you have. – Torbjørn T. Nov 18 '16 at 21:56
  • I'm using 1.12.1 although I have installed the version 1.14... How can I force LaTeX to use the latest version? – Sam Nov 18 '16 at 22:04
  • You would need to provide more information for anyone to answer that I think. Which TeX distribution are you using (TeX Live, MikTeX, MacTeX), and how did you install it (matters for TeX Live at least, I think), and how did you install pgfplots 1.14. Either way, I would recommend either completely rewriting this question, or deleting it altogether and post a new one about the installation issue. – Torbjørn T. Nov 18 '16 at 22:07
  • That said, there are other ways of specifying ticks as well, e.g. xtick={3390,3400,...,3460}. – Torbjørn T. Nov 18 '16 at 22:11
  • 1
    @Rmano Yes, but the code still works (I did test). The compatibility setting (obviously) doesn't remove the xtick distance altogether. And the OP also said that \pgfplotsversion printed 1.12.1 ... – Torbjørn T. Nov 18 '16 at 22:47
1

Based on comments, the problem here is that you're reading the manual for version 1.14, while the actual version you have installed LaTeX is 1.12.1, in which the xtick distance key was not implemented. Instead you can use xtick={3390,3400,...,3460} to specify the tick locations.

You will most likely get the correct manual version if you do texdoc pgfplots from a terminal/command prompt, if not you can get it at https://sourceforge.net/projects/pgfplots/files/pgfplots/1.12.1/.

Seems you have tried installing version 1.14 somehow. If you need help with your installation issues, please ask a new question about that, with more details about your system. You could consider simply upgrading to TeX Live 2016 (see How to install "vanilla" TeXLive on Debian or Ubuntu? if you're on some Ubuntu-like distro).

\documentclass{article}
\usepackage{pgfplots,siunitx}
\pgfplotsset{compat=1.12, width=0.7\linewidth}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    xtick={3390,3400,...,3460},
    xlabel={Magnetic field [\si{G}]},
    ylabel={EPR-Signal [\si{a.u.}]},
    xmin=3390, xmax=3460,
    ]    
    \addplot coordinates {(3400,0)(3450,0)};
    \legend{Experiment}
  \end{axis}
\end{tikzpicture}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.