我有一个以 1 为界的函数图。为了强调 y=-1 和 y=1 是函数图的渐近线,我希望域为区间 [-30, 30] ... 或类似的值。pgfplots
给出的图在垂直方向上的长度大约是我想要的两倍。我该如何减少它?我还希望 x 轴的显示长度大约是给出长度的两倍pgfplots
。我该如何让它更长?
另外,我使用了fill=white
,ticklabel style
这样水平渐近线就不会绘制在刻度线的标签上。为什么渐近线会绘制在标签上?(为什么告诉tex.stackexchange
我“渐近线”拼写错误?!)
\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=3.5in,clip=false,
axis lines=middle,
xmin=-30,xmax=30,
ymin=-1.25,ymax=1.25,
ticklabel style={font=\tiny,fill=white},
xtick={\empty},ytick={\empty},
extra y ticks={-1,1},
extra y tick labels={$-1$,1},
enlargelimits={abs=0.5cm},
axis line style={latex-latex},
xlabel=$x$,ylabel=$y$,
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[samples=201,domain=-30:0,blue] {x / (- x + 1)} node[anchor=south east, pos=0.25,font=\footnotesize]{$y = \dfrac{x}{\vert x \vert + 1}$};
\addplot[samples=201,domain=0:30,blue] {x / (x + 1)};
\addplot[latex-latex,dashed,draw=gray!10,samples=2,domain=-30:30] {-1};
\addplot[latex-latex,dashed,samples=2,draw=gray!10,domain=-30:30] {1};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您可以将图表的宽度设置为高度的两倍,以获得所需的大小。我将渐近线绘制为两个指向左和右的箭头,以避免覆盖标签,并将其涂成灰色以区别于刻度线。
\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=5in,
height=2.5in,
clip=false,
axis lines=middle,
xmin=-30,xmax=30,
ymin=-1.25,ymax=1.25,
ticklabel style={font=\tiny},
xtick={\empty},ytick={\empty},
extra y ticks={-1,1},
extra y tick labels={$-1$,1},
enlargelimits={abs=0.5cm},
axis line style={latex-latex},
xlabel=$x$,ylabel=$y$,
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[samples=201,domain=-30:0,blue] {x / (- x + 1)} node[anchor=south east, pos=0.25,font=\footnotesize]{$y = \dfrac{x}{\vert x \vert + 1}$};
\addplot[samples=201,domain=0:30,blue] {x / (x + 1)};
% Bottom asymptote
\addplot[-latex,dashed,gray,samples=2,domain=1:30] {-1};
\addplot[latex-,dashed,gray,samples=2,domain=-30:-3] {-1};
% Top asymptote
\addplot[-latex,dashed,gray,samples=2,domain=1:30] {1};
\addplot[latex-,dashed,gray,samples=2,domain=-30:-2] {1};
\end{axis}
\end{tikzpicture}
\end{document}