Graphics, Figures & TablesReverse Scaling for Abscissa

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
fruitfrisje
Posts: 10
Joined: Wed Dec 05, 2012 12:26 pm

Reverse Scaling for Abscissa

Post by fruitfrisje »

Hi,

I've created a graph with pgfplots. Now I would like to mirror the abscissa so that the highest number would be on the left, and the smallest number on the right.

Code: Select all

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
  \begin{tikzpicture}
    \begin{semilogxaxis}[
      grid=both,
      enlarge x limits=false,
      scale only axis,
      width=10cm,
      height=6cm,
      ymin=0,
      ymax=1500,
      tick style={draw=none},
      xlabel=Exceedance frequency {[1/year]}, 
      ylabel=Waterlevel with repect to NAP {[cm]}
    ]
      \addplot[color=red,mark=x] coordinates {
        (1/1250,1430)
        (1/100,1340)
        (1/10,1255)
        (1/2,1155)
        (1,1100)
        (2,765)
      };
    \end{semilogxaxis}
  \end{tikzpicture}
\end{document}
I've searched a lot but couldn't find it? Any suggestions on this?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Reverse Scaling for Abscissa

Post by localghost »

In Section 4.9.1 the pgfplots manual introduces the x dir key to determine the scaling direction for the abscissa. You can set this to reverse in your case.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}

\pgfplotsset{
  compat=newest,
  xlabel near ticks,
  ylabel near ticks
}

\begin{document}
  \begin{tikzpicture}
    \begin{semilogxaxis}[
      width=10cm,
      height=6cm,
      grid=both,
      enlarge x limits=false,
      tick style={draw=none},
      scale only axis,
      x dir=reverse,
      xlabel={Exceedance frequency [1/year]},
      ymin=0,
      ymax=1500,
      ylabel={Waterlevel with respect to NAP [cm]}
    ]
      \addplot[color=red,mark=x] coordinates {
        (1/1250,1430)
        (1/100,1340)
        (1/10,1255)
        (1/2,1155)
        (1,1100)
        (2,765)
      };
    \end{semilogxaxis}
  \end{tikzpicture}
\end{document}
The output is attached. For details please refer to the package manual.


Thorsten
Attachments
rtmp.png
rtmp.png (5.03 KiB) Viewed 6235 times
fruitfrisje
Posts: 10
Joined: Wed Dec 05, 2012 12:26 pm

Reverse Scaling for Abscissa

Post by fruitfrisje »

Setting x dir=reverse just did the trick!

Thanks
Post Reply