TransWikia.com

Is there a way to place the x axis at a specific y value in PGFPlots?

TeX - LaTeX Asked by Gern Blanston on February 9, 2021

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}

One Answer

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

Answered by hpekristiansen on February 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP