如何用latex画三角函数图像?

2025-06-29 04:22:32
推荐回答(1个)
回答1:

这是一个使用 PGFplots 的例子,注意在画图的时候,使用的是 sin(deg(x)),因为 sin 的默认参数是角度,所以要想画一个完整的 sin 图像,x 需要 0:360,或者使用 deg 将其转换为角度。

\documentclass{article}


\usepackage{pgfplots}

\pgfplotsset{

    compat=1.16,

}


\begin{document}

    

\begin{tikzpicture}

\begin{axis}[

    xlabel={$x$}, ylabel={$y$},

    xmin=-2*pi, xmax=2*pi,

    ymin=-1.5, ymax=1.5,

    xtick={-6.28319, -3.14159, 0, 3.14159, 6.28319},

    xticklabels={$-2\pi$, $-\pi$, $0$, $\pi$, $2\pi$},

    line width=1pt,

    axis lines=center,

]

    \addplot[smooth,domain=-2*pi:2*pi, red!70]{sin(deg(x))};

\end{axis}

\end{tikzpicture}


\end{document}


效果:

代码截图: