[Tex/LaTex] Aligning ticklabels in secondary y-axis in pgfplot

pgfplotstikz-pgf

I want to right align the ticklabels in secondary y-axiz in pgfplot. Here is my output and MWE. Thanks in advance for your help.

enter image description here

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat = 1.7}

\begin{document}

\begin{tikzpicture}

    \pgfplotsset{
        set layers,% --- CF
        , x tick label style={
             /pgf/number format/.cd,
             fixed,
             fixed zerofill,
             precision=1,
             /tikz/.cd
            }
          , y tick label style={
             /pgf/number format/.cd,
             fixed,
             fixed zerofill,
             precision=1,
             /tikz/.cd
            },
    }

    \begin{axis}[
        %   title = {$x \exp(-x^2-y^2)$}
        , xlabel = $x$
            , ylabel = $y$
            , domain = -1:1
            , y domain = -1:1
        , enlargelimits
        , view = {0}{90}
        , extra description/.code={% --- CF
                \xdef\XMIN{\pgfkeysvalueof{/pgfplots/xmin}}
                \xdef\XMAX{\pgfkeysvalueof{/pgfplots/xmax}}
                \xdef\YMIN{\pgfkeysvalueof{/pgfplots/ymin}}
                \xdef\YMAX{\pgfkeysvalueof{/pgfplots/ymax}}
        },
        ]

       \addplot3[
            contour gnuplot={
                  number = 10
                 },
             thick
            ]
         {
                    776.062 -50.812* x + 153.062 * y -76.812 *x *y
                    };

    \end{axis}

    \begin{axis}[% --- CF
        xmin=\XMIN,
        xmax=\XMAX,
        ymin=\YMIN,
        ymax=\YMAX,
        ticklabel pos=right,
    ]
    \end{axis}

\end{tikzpicture}

\end{document}

Best Answer

Another way, using yticklabel style={anchor=east,xshift=2.75em}. Unfortunately, it still requires manual adjustment (the xshift setting).

I've simplified your MWE significantly so the changes required are not drowned out by other style adjustments. (Also, I don't have gnuplot on this machine.)

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}

\begin{document}
\begin{tikzpicture}
\pgfplotsset{
  set layers,
  domain=-1:1,
  tick label style={
    /pgf/number format/.cd,
    fixed, fixed zerofill,
    precision=1,
    /tikz/.cd,
  },
}
\begin{axis}[xlabel=$x$,ylabel=$y$]
  \addplot[thick] {x^3};
\end{axis}
\begin{axis}[
  ticklabel pos=right,
  yticklabel style={anchor=east,xshift=2.75em},
]
  \addplot {-x^3};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Related Question