17

I want to reverse to direction of the x axis in one of my plots. pgfplots offers the x dir=reverse key for this. However, this does not work as expected - not even in this example:

\documentclass{standalone} 
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.3}
\begin{document}
  \begin{tikzpicture}
    \begin{axis}[xmin=0,xmax=1,x=15cm,
                  ymin=0,ymax=1,y=10cm,
                  x dir=reverse]
      \addplot coordinates{(0,0) (1,1)};
    \end{axis}
  \end{tikzpicture}
\end{document}

In the compiled pdf, the plot starts with (0,0) at the left side, just like it would without the x dir=reverse option.

I have pgfplots 1.5 installed.

What's wrong here?

  • The problem is the x=15cm. – qubyte Feb 2 '12 at 9:50
  • 3
    UPDATE: this is (was) actually a bug in pgfplots. Starting with pgfplots 1.6, the example works flawlessly. – Christian Feuersänger Mar 27 '13 at 19:37
14

The problem is with how you're trying to set the width of the plot. Try this instead:

\documentclass{standalone} 
\usepackage{pgfplots}
%
\pgfplotsset{compat=1.5, width=15cm, height=10cm, scale only axis}
%
\begin{document}
%
  \begin{tikzpicture}
    \begin{axis}[
      xmin=0,
      xmax=1,
      ymin=0,
      ymax=1,
      x dir=reverse
    ]
      \addplot coordinates{(0,0) (1,1)};
    \end{axis}
  \end{tikzpicture}
%
\end{document}

Your plots axes will all be the same size unless otherwise specified.

5

It is due to your placement of x=15cm. What reverse does is simply x=-x. So in your case you can do:

\begin{axis}[xmin=0,xmax=1,x=-15cm,
              ymin=0,ymax=1,y=10cm]
  \addplot coordinates{(0,0) (1,1)};
\end{axis}

It is the equivalent of reversing the axis.

However, x= has precedence over x dir which is why you get the setting you have.

  • I feel dumb now. – Christoph Feb 2 '12 at 9:48
  • 1
    Don't, it isn't obvious unless you know it. :) – zeroth Feb 2 '12 at 9:49

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.