[Tex/LaTex] Make a smoother plot of functions with pgfplots

pgfplotstikz-pgf

The following code gives me a plot which is not very smooth. It looks like several points (with spacing 0.5 in the horizontal direction) are drawn first and then connected by straight lines. What options do I have to modify to make it smoother? Thanks.

\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}

enter image description here

Best Answer

You can use the option 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}

smooth plot