5

I prefer single-line axes for plots, rather than the box style which is (I think) the default for PGFPlots. I'm familiar with the axis x line*=middle option, which places the x-axis at y=0. However, I often need to graph temperature data where it would make much more sense to show the axis at y=20 (with data in °C). I haven't been able to find a way to do this. Is there some way to make this happen?

I'd prefer not to just use a \draw command to manually create the axis because then I would need to manually create ticks, labels, etc.


Edit to clarify what I'm asking:

I'd like to achieve this, but without the kludge for the x-axis. enter image description here

\documentclass[margin=3mm]{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

    \begin{document}
\begin{tikzpicture}
    \begin{axis}[
    axis x line=none,
    axis y line=middle,
    xmin=0,
    ymin=5,
    ymin= 10,
    ymax=30,
    xlabel=$x$,
    ylabel=$y$,
    ]

    \addplot coordinates {(0,20) (1,24) (2,28) (3,18) (4,21) (5,27)};
    \coordinate (start) at (axis cs:0,20);
    \coordinate (end)   at (axis cs:5,20);
    \end{axis}

    \draw[->] (start) -- (end);

\end{tikzpicture}
\end{document}

1 Answer 1

12

axis x line shift shifts x axis down, and a negative number shifts it up. From y min=10 up to 20 gives -10.

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        axis lines=center,
        axis x line shift=-10,
        xmin=0,
        xmax=5,
        ymin=10,
        ymax=30,
        xlabel=$x$,
        ylabel=$y$,
    ]
    \addplot coordinates {(0,20) (1,24) (2,28) (3,18) (4,21) (5,27)};
    \end{axis}
\end{tikzpicture}
\end{document}

Graph with x-axis at y=20

1
  • 1
    Thank you, this is exactly what I was looking for! Commented Dec 6, 2018 at 21:45

You must log in to answer this question.

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