我尝试根据与参考值的比较将 y 刻度定位到轴的左侧和右侧。比如在下图中,我想将正 y 标签定位到轴的左侧,将负 y 标签定位到轴的右侧。
代码如下(它是来自以前的邮政局)
\documentclass{article}
\usepackage{tikz,pgfplots}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[>=latex]
\begin{axis}[
axis x line=center,
axis y line=center,
xtick={-5,-4,...,5},
ytick={-5,-4,...,5},
xlabel={$x$},
ylabel={$y$},
xlabel style={below right},
ylabel style={above left},
xmin=-5.5,
xmax=5.5,
ymin=-5.5,
ymax=5.5]
\end{axis}
\end{tikzpicture}
\end{document}
答案1
你可以使用这样的东西:
\documentclass{article}
\usepackage{tikz,pgfplots}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[>=latex]
\begin{axis}[
axis x line=center,
axis y line=center,
xtick={-5,-4,...,5},
ytick={0,1,...,5},
xlabel={$x$},
ylabel={$y$},
xlabel style={below right},
ylabel style={above left},
xmin=-5.5,
xmax=5.5,
ymin=-5.5,
ymax=5.5,
extra y ticks={-5,-4,-3,-2,-1},
extra y tick style={yticklabel style={xshift=0.5ex, anchor=west}}
]
\end{axis}
\end{tikzpicture}
\end{document}
然而,正如上面评论的那样,勾选标签会干扰