如何在 pgfplots 中使用 sin 函数?在这篇文章中与 TikZ PGFlots 的计时和集成我只需要
[/pgf/declare function={f=sin(x);}]
生成一条线,但[/pgf/declare function={f=sin(x r);}]
不起作用。
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\pgfplotsset{
integral segments/.code={\pgfmathsetmacro\integralsegments{#1}},
integral segments=3,
integral/.style args={#1:#2}{
ybar interval,
domain=#1+((#2-#1)/\integralsegments)/2:#2+((#2-#1)/\integralsegments)/2,
samples=\integralsegments+1,
x filter/.code=\pgfmathparse{\pgfmathresult-((#2-#1)/\integralsegments)/2}
}
}
\begin{tikzpicture}[/pgf/declare function={f=sin(x);}]
\begin{axis}[
domain=0:10,
samples=100,
axis lines=middle
]
\addplot [
fill=yellow,
integral segments=20,
integral=-6:6
] {f};
\addplot [thick] {f};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
如果用 替换/pgf/declare function={f=sin(x);}
,/pgf/declare function={f=sin((x)r);}
函数将按预期绘制,x
值表现为弧度。如果还将integral
域更改为0:2*pi
,则会得到以下输出: