如何標示有理函數 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
and 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 使用垂直線 through和水平線 through(c1 |- c2)
的交點處的座標。換句話說:從 開始,向上或向下(沿 y 方向)移動,直到位於 旁邊。這是您指定的點。c1
c2
c1
c2
類似地,(c1 -| c2)
與穿過 的水平線c1
和穿過 的垂直線相交c2
。
PGF 手冊(不是 PGFplots 手冊)第 13.3 節交點座標對此進行了更詳細的解釋。