11

Judging from the pgfplots manual I expected the following code to work:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{figure}
  \begin{tikzpicture}
    \begin{axis}[
      xmin=0,
      xmax=4,
      ymin=0,
      ymax=4,
      ]
      \draw (1,1) -- (3,2);
    \end{axis}
  \end{tikzpicture}
\end{figure}
\end{document}

However, it doesn't - meaning that it seems the \draw command does nothing at all. I just get an empty axes with no line.

enter image description here

Can anyone shed some light on this? I guess the solution will be really easy...

1 Answer 1

16

You need to add the compat option to tell pgfplots which version you want to use. The most recent version is 1.11, or you can use the keyword newest to always use the newest version. Note that the default behavior of assigning points was changed in v1.11, so you need to set the compatibility equal to or newer than that. Note also that the newest syntax is not recommended according to the package author (or at least, you should know you have a reason to use newest instead of an explicit version).

\documentclass{article}
\usepackage{pgfplots}
%\pgfplotsset{compat=newest} %<------ Here
\pgfplotsset{compat=1.11} %<------ Or use this one
\begin{document}
\begin{figure}
  \begin{tikzpicture}
    \begin{axis}[
      xmin=0,
      xmax=4,
      ymin=0,
      ymax=4,
      ]
      \draw (1,1) -- (3,2);
    \end{axis}
  \end{tikzpicture}
\end{figure}
\end{document}

In fact, if you look at the log for the OP MWE (without the compat being set), you find the following message:

Package pgfplots Warning: running in backwards compatibility mode (unsuitable t
ick labels; missing features). Consider writing \pgfplotsset{compat=1.11} into 
your preamble.
 on input line 4.

which tells you most of what you need to know!

8
  • D'oh... I just removed the line after updating from 1.6 to 1.11 while trying to get it to work. The older version produced an error without the compat line, the newer didn't, so I removed it. So to conclude: The real problem here was with version 1.6 that for some reason did not plot the line. Updating fixed the issue.
    – Eike P.
    Commented Nov 6, 2014 at 14:28
  • 2
    Version 1.6 probably did plot the line, just outside the bounds of your axes. If you add the explicit (axis cs: 1,1) -- (axis cs: 3,2);, you should see the line in all versions (you can verify by changing the version in the compat setting)
    – darthbith
    Commented Nov 6, 2014 at 14:30
  • 1
    Ahhh you're right! Good to know and thanks a lot for the help! :)
    – Eike P.
    Commented Nov 6, 2014 at 14:32
  • @jhin Happy to help!
    – darthbith
    Commented Nov 6, 2014 at 14:32
  • Good answer. Related question : tex.stackexchange.com/questions/139690/… Commented Nov 6, 2014 at 22:17

You must log in to answer this question.

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