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

  • 4
    Set the option samples=<number> – Paul Gessler May 25 '16 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. – Henri Menke May 25 '16 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 '16 at 15:15
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

| improve this answer | |
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

| improve this answer | |

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.