以下代码给出了一个不太平滑的图。它看起来像是先绘制几个点(水平方向上的间距为 0.5),然后用直线连接。我必须修改哪些选项才能使其更平滑?谢谢。
\documentclass[]{standalone}
\usepackage{xcolor}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
scale=0.8,
axis lines=middle,
grid=major,
xmin=-5,
xmax=5,
ymin=-5,
ymax=5,
xlabel=$x$,
ylabel=$y$,
xtick={-4,-3,...,5},
ytick={-4,-3,...,4},
tick style={very thick}
]
\addplot[domain=-6:6, blue, ultra thick] {x^3-x};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您可以使用以下选项smooth
:
\documentclass{standalone}
\usepackage{xcolor}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
scale=0.8,
axis lines=middle,
grid=major,
xmin=-5,
xmax=5,
ymin=-5,
ymax=5,
xlabel=$x$,
ylabel=$y$,
xtick={-4,-3,...,5},
ytick={-4,-3,...,4},
tick style={very thick},
smooth
]
\addplot[domain=-6:6, blue, ultra thick] {x^3-x};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
我发现包中的宏更容易tkz-fct
绘制图形
\documentclass{standalone}
\usepackage{tkz-fct}
\begin{document}
\begin{tikzpicture}
\tkzInit[xmin=-5,xmax=5,ymin=-5,ymax=5]
\tkzGrid[color=gray!40,line width=0.2pt]
\tkzDrawX[color=black,label={$x$},above left=5pt]
\tkzLabelX[color=black]
\tkzDrawY[color=black,label={$y$},below right=5pt]
\tkzLabelY[color=black,orig=false]
\tkzFct[domain=-2:2,color=red,line width=1.5pt]{x**3-x}
\end{tikzpicture}
\end{document}