What can I do to smooth the curve? (LaTeX, PGFplots)

472 Views Asked by At

I am trying to plot a graph of cos(sin(x)) and the line isn't smooth at all. I've tried to increase the number of samples as well as adding 'smoothing' and messing around with the tension values, but neither worked. Is there any way to fix this? Below is the code and output. Thank you!

\begin{tikzpicture}
    \begin{axis}[
        axis y line=middle, 
        axis x line=middle, 
        grid=both,
        enlarge y limits=true,
        xlabel={\(x\)},
        ylabel={\(\cos{(\sin{(x)})}\)},
        xtick={
           -2*pi, -(3*pi)/2, -pi, -pi/2,
           pi/2, pi, (3*pi)/2, 2*pi
        },
        xticklabels={
           $-2\pi$, $-\frac{3\pi}{2}$, $-\pi$, $-\frac{\pi}{2}$,
           $\frac{\pi}{2}$, $\pi$, $\frac{3\pi}{2}$, $2\pi$
        },
        domain=-2*pi:2*pi 
    ]
    \addplot [ 
        samples=1000, 
        color=red,
       ]
       {cos(sin(deg(x)))};
    \end{axis}
    \end{tikzpicture}\\ \vspace*{0.7cm}

Output graph

1

There are 1 best solutions below

2
Federico On

You need to pass the option samples=1000 in the \begin{axis} options and not in the \addplot. Example code below.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        width=12cm,
        height=7cm,
        xlabel={\(x\)},
        ylabel={\(\cos{(\sin{(x)})}\)},
        grid=both,
        samples=200,
        axis y line=middle, 
        axis x line=middle, 
    ]
    \addplot[blue, thick, domain=-360:360] {cos(deg(sin(x)))};
    \end{axis}
\end{tikzpicture}
\end{document}