我正在使用 pgfplots\addplot3
绘制二元函数的轮廓图,如 (x,y) 平面所示 (使用view={0}{90}
)。但是轴标签的默认位置很奇怪 (我怀疑,因为它们是 3D 的)。
我希望 x 位于 x 轴箭头的右侧,y 位于 y 轴箭头的上方。我已遵循此问题,但改变锚点xlabel style
似乎并没有改变图表上的任何东西。
梅威瑟:
\documentclass{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{
% use `compat' level 1.8 or higher
compat=1.8,
% just put all the options in here and it will work as expected
every axis/.append style={
axis lines=center,
xlabel style={anchor=south west},
ylabel style={anchor=south west},
zlabel style={anchor=south west},
tick align=outside,
},
}
\begin{document}
\begin{tikzpicture}[scale=0.85,font=\large]
\begin{axis}[ ,
axis lines=center,
view={0}{90},
xlabel=$x$, ylabel=$y$,
]
\addplot3 [
contour gnuplot={levels={0.5,2}},
domain=0:2,y domain=0:2
] {2*x*y };
\end{axis}
\end{tikzpicture}
\end{document}
答案1
似乎在中定义轴标签样式\pgfplotset
不会将样式属性传递给 Gnuplot。因此,您必须在轴环境中定义它。您还可以使用以下命令控制标签的位置:
x label style={at={(axis description cs:1.1,0.0)},anchor=center},
梅威瑟:
\documentclass{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{
% use `compat' level 1.8 or higher
compat=1.8,
}
\begin{document}
\begin{tikzpicture}[scale=0.85,font=\large]
\begin{axis}[ ,
axis lines=center,
view={0}{90},
xlabel=$x$, ylabel=$y$,
% x label style={anchor=south west},
% y label style={anchor=south west},
x label style={at={(axis description cs:1.1,0.0)},anchor=center},
y label style={at={(axis description cs:0.0,1.1)},anchor=center},
]
\addplot3 [
contour gnuplot={levels={0.5,2}},
domain=0:2,y domain=0:2
] {2*x*y};
\end{axis}
\end{tikzpicture}
\end{document}
附言:弗拉基米尔比我快...:)
答案2
您可以在轴环境中指定轴标签的位置。
\documentclass{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{
% use `compat' level 1.8 or higher
compat=1.8,
% just put all the options in here and it will work as expected
every axis/.append style={
axis lines=center,
tick align=outside,
},
}
\begin{document}
\begin{tikzpicture}[scale=0.85,font=\large]
\begin{axis}[ ,
axis lines=center,
view={0}{90},
xlabel style={right, yshift=5pt},
ylabel style={above, xshift=5pt},
xlabel=$x$, ylabel=$y$,
domain=0:2,y domain=0:2,
]
\addplot3 [
contour gnuplot={levels={0.5,2}},
samples=50,
] {2*x*y };
\end{axis}
\end{tikzpicture}
\end{document}
和xshift
参数yshift
可以省略。