我想右对齐次级 y 轴上的刻度标签pgfplot
。这是我的输出和 MWE。提前感谢您的帮助。
\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}
答案1
另一种方法是使用yticklabel style={anchor=east,xshift=2.75em}
。不幸的是,它仍然需要手动调整(xshift
设置)。
我已经大大简化了您的 MWE,因此所需的更改不会被其他样式调整所淹没。(另外,我在这台机器上没有gnuplot
。)
\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}
答案2
来自关联由@Torbjørn 给出,使用yticklabel style={draw,text width=width("$-2.0$"),align=right}
就可以了。
\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,
yticklabel style={text width=width("$-2.0$"),align=right}
]
\end{axis}
\end{tikzpicture}
\end{document}