\documentclass{article}
\usepackage{pgfplots}
\def\FunctionF(#1){(#1)^3- 3*(#1)}%
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis y line=center,
axis x line=middle,
axis on top=true,
xmin=-5.5,
xmax=5.5,
ymin=-45,
ymax=45,
height=12.0cm,
width=12.0cm,
grid,
xtick={-5,...,5},
ytick={-40,-32,...,40},
]
\addplot [domain=-5:5, samples=50, mark=none, ultra thick, blue] {\FunctionF(x)};
\node [left, blue] at (axis cs: 3.6,42) {$x^3-3x$};
\end{axis}
\end{tikzpicture}
\end{document}
但我需要添加这个,就像你看到的红色一样
如何添加对应点,如果可以用不同的颜色更好
并且,在轴交叉点的中心添加零,因为水平方向从 -1 跳到 1,垂直方向从 -8 跳到 8。
谢谢
答案1
像这样?
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
declare function = {f(\t)=(\t)^3- 3*(\t);},
height=12.0cm,
width=12.0cm,
axis lines=center,
grid,
xmin=-5.5,
xmax=5.5,
ymin=-45,
ymax=45,
ticklabel style = {font=\footnotesize, inner sep=1pt,
fill=white},
xtick={-5,...,2,4,5},
ytick={-40,-32,...,40},
extra x ticks = {0,3},
extra y ticks = {18},
extra x tick style = {grid=none, color=red},
extra y tick style = {color=red}
]
\addplot +[domain=-5:5, samples=51, mark=none, ultra thick] {f(x)}
node [pos=0.7, left=2mm] {$x^3-3x$};
\draw[dashed, semithick, red] (3,0) |- (0,18) node[pos=0.5, circle, inner sep=2pt, fill=red] {};
\end{axis}
\end{tikzpicture}
\end{document}