6

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

3
  • 4
    Set the option samples=<number> May 25, 2016 at 2:42
  • 2
    @PaulGessler (initially 25) Also it is advantageous to use an odd number of samples for a symmetric domain to have 0 included. May 25, 2016 at 17:36
  • Since you are using only the domain [-2,2] you can set it so to use more samples in that domain
    – percusse
    May 26, 2016 at 15:15

2 Answers 2

5

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

2

I find easier the macros in the tkz-fct package in order to plot graphs

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

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.