21

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?

2
  • The problem is the x=15cm.
    – qubyte
    Commented Feb 2, 2012 at 9:50
  • 3
    UPDATE: this is (was) actually a bug in pgfplots. Starting with pgfplots 1.6, the example works flawlessly. Commented Mar 27, 2013 at 19:37

2 Answers 2

24

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.

0
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.

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

You must log in to answer this question.

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