如何标记有理函数 y=(x+1)/(x-1) 的渐近线?我\draw[dashed,latex-latex] ({{1,0}}|-{{axis description cs:1,1}}) -- ({{1,0}}|-{{axis description cs:1,0}})
从另一篇文章中复制了代码。我在手册中查找了此编码。我从手册中得到的唯一“信息”是“轴描述 cs”是“坐标系 (cs)”的一些描述,而 {1,1} 指的是某个框的右上角。我认为“|-”指示 TikZ 绘制一条垂直线。
我不知道如何修改代码让 TikZ 绘制水平渐近线 y=1。如何将标签“x=1”放在底部箭头处,将“y=1”放在左侧箭头处?
\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=4in,axis equal image,
axis lines=middle,
xmin=-15,xmax=15,
xlabel=$x$,ylabel=$y$,
ymin=-10,ymax=10,
restrict y to domain=-12:12,
enlargelimits={abs=1cm},
axis line style={latex-latex},
ticklabel style={font=\tiny,fill=white},
xtick={-3}
]
/pgfplots/xlabel shift={10pt};
\addplot[samples=250,domain=-15:15] {(x+2)/(x-1)};
\draw[dashed,shorten <=2ex, shorten >=2ex,latex-latex] ({{1,0}}|-{{axis description cs:1,1}}) -- ({{1,0}}|-{{axis description cs:1,0}});
\draw [fill=white] (-3,0.25) circle [radius=1.5pt] node[left]{};
\end{axis}
\end{tikzpicture}
\vskip0.25in
\begin{tikzpicture}
\begin{axis}[width=4in,axis equal image,
axis lines=middle,
xmin=-15,xmax=15,
xlabel=$x$,ylabel=$y$,
ymin=-10,ymax=10,
restrict y to domain=-12:12,
enlargelimits={abs=1cm},
axis line style={latex-latex},
ticklabel style={font=\tiny,fill=white},
xtick={-1},ytick=\empty
]
/pgfplots/xlabel shift={10pt};
\addplot[samples=251,domain=-14:16] {(x+1)/(x-1)};
\draw[dashed,shorten <=2ex, shorten >=2ex,latex-latex] ({{1,0}}|-{{axis description cs:1,1}}) -- ({{1,0}}|-{{axis description cs:1,0}});
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您可以使用 anode
来放置x=1
和y=1
。此外,要在 处绘制水平线y=1
,您可以使用\addplot
:例如
\addplot[samples=200,dashed,latex-latex,domain=-17:17] {1}node[above,pos=0]{$y=1$};
完整代码:
\documentclass[10pt]{amsart}
%\usepackage{tikz} %% These are all not needed
%\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
%\usepackage{tkz-euclide}
%\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
%\usepackage{amsmath}
%\usepackage{amsfonts}
%\usepackage{amssymb}
%\usepackage{amsthm}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=4in,axis equal image,
axis lines=middle,
xmin=-15,xmax=15,
xlabel=$x$,ylabel=$y$,
ymin=-10,ymax=10,
restrict y to domain=-12:12,
enlargelimits={abs=1cm},
axis line style={latex-latex},
ticklabel style={font=\tiny,fill=white},
xtick={-3},
every axis y label/.style=
{at={(ticklabel cs:1.02,-12pt)},rotate=0,anchor=west},
every axis x label/.style={
at={(xticklabel cs:1.02,-8pt)},anchor=south},
]
/pgfplots/xlabel shift={10pt};
\addplot[samples=250,domain=-15:15] {(x+2)/(x-1)};
\draw[dashed,shorten <=2ex, shorten >=2ex,latex-latex] ({{1,0}}|-{{axis description cs:1,1}}) -- ({{1,0}}|-{{axis description cs:1,0}})node[right,pos=0.95]{$x=1$};
\draw [fill=white] (-3,0.25) circle [radius=1.5pt] node[left]{};
\addplot[samples=200,dashed,latex-latex,domain=-17:17] {1}node[above,pos=0]{$y=1$};
\end{axis}
\end{tikzpicture}
\vskip0.25in
\begin{tikzpicture}
\begin{axis}[width=4in,axis equal image,
axis lines=middle,
xmin=-15,xmax=15,
xlabel=$x$,ylabel=$y$,
ymin=-10,ymax=10,
restrict y to domain=-12:12,
enlargelimits={abs=1cm},
axis line style={latex-latex},
ticklabel style={font=\tiny,fill=white},
xtick={-1},ytick=\empty,
every axis y label/.style=
{at={(ticklabel cs:1.02,0pt)},rotate=0,},
every axis x label/.style={
at={(xticklabel cs:1.02,-8pt)},anchor=south},
]
/pgfplots/xlabel shift={10pt};
\addplot[samples=251,domain=-14:16] {(x+1)/(x-1)};
\draw[dashed,shorten <=2ex, shorten >=2ex,latex-latex] ({{1,0}}|-{{axis description cs:1,1}}) -- ({{1,0}}|-{{axis description cs:1,0}})node[right,pos=0.95]{$x=1$};
\addplot[samples=200,dashed,latex-latex,domain=-17:17] {1}node[above,pos=0]{$y=1$};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
该语法指示 TikZ 使用通过 的垂直线和通过 的水平线(c1 |- c2)
的交点处的坐标。换句话说:从 开始,然后向上或向下(沿 y 方向)移动,直到到达 旁边。这是您指定的点。c1
c2
c1
c2
类似地,(c1 -| c2)
与一条水平线相交c1
,并与一条垂直线相交c2
。
PGF 手册(不是 PGFplots 手册)第 13.3 节“交叉点坐标”对此进行了更详细的解释。