pgfplots 中是否有任何方法可以描述轴上方 x 轴标签的正部分以及轴下方 x 轴标签的负部分?关键是,如果函数的图形部分位于轴上方,部分位于轴下方,那么我无法做到这一点,至少轴上的标签部分不会覆盖函数图形。
\documentclass{minimal}
\usepackage{pgfplots}
\def\AddLabel(#1,#2)#3{\node \[align = center\] at (axis cs: #1,#2) {#3};}%
\begin{document}
\begin{tikzpicture}
\def\function{rad(atan((1.73205*\x)/(1-(\x)^2)))}
\def\functionlabel{\arctan\frac{\sqrt{3}\cdot x}{1-x^2}}
\begin{axis}\[
xmin=-10,
xmax=10,
domain=-9.5:9.5,
ymin=-3,
ymax=3,
y domain=-3:3,
width=\textwidth,
height=0.4\textwidth,
axis x line=middle,
axis y line=middle,
axis equal=true,
xlabel=$x$,
ylabel=$y$,
samples=600,
clip=true,
xticklabel style={anchor=north,yshift=5mm},
yticklabel style={anchor=west,xshift=0.5mm},
\]
\addplot\[line width=1.5pt,domain=-9.5:-1.01,y domain=-3:3\]{\function};
\addplot\[line width=1.5pt,domain=-0.99:0.99, y domain=-3:3\]{\function};
\addplot\[line width=1.5pt,domain=1.01:9.5,y domain=-3:3\]{\function};
\AddLabel(4,-1.5){$f\!:\ y=\functionlabel$}
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您可以对轴的一半使用正常刻度,extra x ticks
对另一半使用正常刻度,然后设置every extra x tick/.style={xticklabel style={anchor=north}}
:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\def\function{rad(atan((1.73205*\x)/(1-(\x)^2)))}
\begin{axis}[
xmin=-10,
xmax=10,
domain=-9.5:9.5,
ymin=-3,
ymax=3,
y domain=-3:3,
axis x line=middle,
axis y line=middle,
axis equal image,
samples=50,
clip=true,
xticklabel style={anchor=south},
yticklabel style={anchor=west,xshift=0.5mm},
xtick={5,10},
extra x ticks={-10,-5},
every extra x tick/.style={
xticklabel style={anchor=north}
}
]
\addplot[line width=1.5pt,domain=-9.5:-1.01,y domain=-3:3]{\function};
\addplot[line width=1.5pt,domain=-0.99:0.99, y domain=-3:3]{\function};
\addplot[line width=1.5pt,domain=1.01:9.5,y domain=-3:3]{\function};
\end{axis}
\end{tikzpicture}
\end{document}