英文:
What can I do to smooth the curve? (LaTeX, PGFplots)
问题
我试图绘制cos(sin(x))的图表,但线条一点也不平滑。我已经尝试增加样本数量以及添加“平滑”并调整张力值,但都没有起作用。有没有办法解决这个问题?以下是代码和输出。谢谢!
英文:
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}
答案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}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论