0

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 Answers1

1

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}
Federico
  • 612
  • 7
  • 7
  • Thank you, but this hasn't made a difference at all; it looks just as choppy as it did before. Maybe it's an issue with the compiler I'm using? – SpaceWarriorR May 25 '23 at 16:09
  • Yes, it must be an issue with the compiler or perhaps you may need to update the pgfplots package. Just compile the code I shared with you on overleaf and you will see that it works. – Federico May 27 '23 at 03:30