
我期望在 (2,2) 處看到一個實心黑色圓形點,但我什麼也沒看到。
這是我正在使用的程式碼
\documentclass[]{article}
\usepackage{amsmath}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
restrict y to domain=-10:10,
restrict x to domain=-5:5,
xlabel=$x$,
ylabel=$y$,
xmin=-4,
xmax=4,
xtick={-4,-2,...,4},
ymin=-4,
ymax=4,
ytick={-4,-2,...,3},
axis lines=center,
axis equal,
smooth,
scale=0.8
]
\addplot [] {(x-2)^3-3*x+6};
\coordinate
[
label=above:{$(2,2)$},
black,
mark=*,
] (a) at (axis cs:2,2);
\end{axis}
\end{tikzpicture}
\end{document}
很明顯,軟體可以計算出 (2,2) 處有一個座標,但只是沒有顯示它。有人知道為什麼會發生這種情況?
答案1
坐標沒有(節點)內容。為了保持語法幾乎完全,我添加了一種cmark
在座標中心添加繪圖標記的樣式。
\documentclass[]{article}
\usepackage{amsmath}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[cmark/.style={label={[anchor=center]:\pgfuseplotmark{#1}}}]
\begin{axis}
[
restrict y to domain=-10:10,
restrict x to domain=-5:5,
xlabel=$x$,
ylabel=$y$,
xmin=-4,
xmax=4,
xtick={-4,-2,...,4},
ymin=-4,
ymax=4,
ytick={-4,-2,...,3},
axis lines=center,
axis equal,
smooth,
scale=0.8
]
\addplot [] {(x-2)^3-3*x+6};
\coordinate
[
label=above:{$(2,2)$},
black,
cmark=*,
] (a) at (axis cs:2,2);
\end{axis}
\end{tikzpicture}
\end{document}
其他選項包括使用node
s。請注意,如果您使用足夠新的 pgfplots 版本,例如\pgfplotsset{compat=1.16}
,則不需要前綴axis cs:
。