3

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?

1
  • 1
    You can add a second axis with axis y line*=right and add the y ticks to that one. As long as ymin and ymax for both axes coincide that works. – user230294 Dec 10 '20 at 18:00
3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.