TransWikia.com

Placing some tick labels on the right in pgfplots

TeX - LaTeX Asked by schtandard on April 21, 2021

Consider the following plot.

documentclass{scrartcl}

usepackage{pgfplots}

begin{document}

begin{tikzpicture}
  begin{axis} [
        width=5cm,
        height=7cm,
        domain=-90:90,
        xtick={-90, 0, 90},
        ytick={-1, .6, 1, -.2},
      ]
    addplot {sin(x)};
    addplot {.2 - .4*sin(x)};
  end{axis}
end{tikzpicture}

end{document}

MWE output

Say I want to have the tick labels for the y coordinates -1 and 0.6 on the left, but the ones for -0.2 and 1 on the right. How can I do that?

One Answer

You could use a conditional style. Here I reordered the ticks and use the axis width to specify the xshift.

% arara: lwpdflatex
documentclass[tikz,margin=3pt]{standalone}

usepackage{pgfplots}
pgfplotsset{compat=1.17}
begin{document}

begin{tikzpicture}
    begin{axis} [
            scale only axis,
            width=5cm,
            height=7cm,
            domain=-90:90,
            xtick={-90, 0, 90},
            ytick={-1,-0.2,0.6,1},
            every y tick label/.append style={
                xshift={isodd(ticknum) ? pgfkeysvalueof{/pgfplots/width} : "0pt"},
                anchor={isodd(ticknum) ? 180 : 0}
            },
        ]
        addplot {sin(x)};
        addplot {.2 - .4*sin(x)};
    end{axis}
end{tikzpicture}
end{document}

enter image description here

Answered by BambOo on April 21, 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