# Placing some tick labels on the right in pgfplots

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},
]
\end{axis}
\end{tikzpicture}

\end{document}


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?

• 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

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}
},
]