我可以怎么做来平滑曲线?(LaTeX,PGFplots)

huangapple go评论81阅读模式
英文:

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

问题

我试图绘制cos(sin(x))的图表,但线条一点也不平滑。我已经尝试增加样本数量以及添加“平滑”并调整张力值,但都没有起作用。有没有办法解决这个问题?以下是代码和输出。谢谢!

Output graph

英文:

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

得分: 1

你需要在\begin{axis}选项中传递选项samples=1000,而不是在\addplot中。示例代码如下。

\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=1000,
        axis y line=middle, 
        axis x line=middle, 
    ]
    \addplot[blue, thick, domain=-360:360] {cos(deg(sin(x)))};
    \end{axis}
\end{tikzpicture}
\end{document}
英文:

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}

huangapple
  • 本文由 发表于 2023年5月25日 01:26:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76326036.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定