
提供的程式碼指示 TikZ 繪製 y = (x^{2} - 4)/(x + 2) 的圖形。需要進行一些修改。該圖看起來像線 y = x - 2。
如何取得位於右箭頭下方稍右的 x 軸上的標籤 $x$,以及如何取得位於右側箭頭上方稍微右側的 y 軸上的標籤 $y$頂部箭頭?如何在scriptstyle
白框中排版刻度線“-2” - 我不希望在其上繪製點 (-2,0) 和 (-2,-4) 之間的虛線。如何縮短 y 軸?畫得太低了。
我在軸的程式碼中有兩個命令:xmax=8,ymax=7
和restrict y to domain=-7:10
。他們指示 TikZ 畫什麼?為什麼沒有xmin
和ymin
命令?
\documentclass[10pt]{amsart}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\begin{document}
\hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[axis equal image,
xmax=8,ymax=7,
axis lines=middle,
restrict y to domain=-7:7,
enlargelimits={abs=1cm},
axis line style={latex-latex},
ticklabel style={fill=white},
ytick=\empty,
xtick={-2}
%xlabel=$x$,ylabel=$y$,
]
\addplot[domain=-10:10,mark=none,samples=10] {x - 2} node [above left, yshift=3pt]{$\scriptstyle{y}=\frac{x^{\scriptscriptstyle{2}} - 4}{x + 2}$};
\draw [thin,dashed] (-2,0) -- (-2,-4);
\draw [fill=white] (-2,-4) circle [radius=1.5pt] node[left]{$\scriptstyle{(-2, \, -4)}$};
\end{axis}
\end{tikzpicture}
\hspace{\fill}
\end{document}
答案1
你現在一定已經明白了這一點,但以防萬一其他人看到這一點並感到好奇。
- 箭頭:與您用於軸的方法基本上相同,添加
<->
到\addplot
選項中。 軸標籤的位置:更改錨點
xlabel style={anchor=north west}, ylabel style={anchor=south west}
- 刻度標籤字體大小:
font=\scriptsize
加到ticklabel style
. - 勾選線下方的標籤: 簡單的方法就是添加
axis on top
到axis
選項中。 xmin
/ymin
:我不明白你為什麼說這些鍵不存在。他們是這樣。設定ymin
是縮短 y 軸的方式。restrict y to domain
:正如我所想的那樣,它過濾掉給定域之外的 y 值。
\documentclass[10pt]{amsart}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis on top, % added
axis equal image,
xmax=8,ymax=7,
xmin=-3,ymin=-4,
axis lines=middle,
restrict y to domain=-7:7,
enlargelimits={abs=1cm},
axis line style={latex-latex},
ticklabel style={fill=white,font=\scriptsize}, % added font
ytick=\empty,
xtick={-2},
xlabel=$x$,ylabel=$y$,
xlabel style={anchor=north west}, % added
ylabel style={anchor=south west}, % added
]
\addplot[domain=-10:10,mark=none,samples=10,<->] {x - 2} node [above left, yshift=3pt]{$\scriptstyle{y}=\frac{x^{\scriptscriptstyle{2}} - 4}{x + 2}$};
\draw [thin,dashed] (-2,0) -- (-2,-4);
\draw [fill=white] (-2,-4) circle [radius=1.5pt] node[left]{$\scriptstyle{(-2, \, -4)}$};
\end{axis}
\end{tikzpicture}
\end{document}