You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求指导使用TikZ与pgfplots在LaTeX中绘制指定图像

使用TikZ和pgfplots绘制目标图像的完整LaTeX代码

以下是生成对应正弦曲线图像的完整代码,包含坐标轴标注、曲线绘制、关键参数(周期、振幅)的标注:

\documentclass[tikz,border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17} % 指定兼容版本避免兼容性问题

\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        axis lines = middle, % 坐标轴在中心交汇
        xlabel = $x$, % x轴标签
        ylabel = $y$, % y轴标签
        xmin=-0.5, xmax=6.8, % x轴显示范围
        ymin=-1.2, ymax=1.2, % y轴显示范围
        xtick={0,1.5708,3.1416,4.7124,6.2832}, % x轴刻度对应0、π/2、π、3π/2、2π
        xticklabels={$0$, $\frac{\pi}{2}$, $\pi$, $\frac{3\pi}{2}$, $2\pi$}, % 刻度的数学符号标签
        ytick={-1,0,1}, % y轴刻度
        yticklabels={$-1$, $0$, $1$}, % y轴刻度标签
        grid = major, % 显示主网格
        grid style={dashed, gray!30}, % 网格设为灰色虚线
        every axis label/.style={font=\large}, % 标签字体大小
        tick label style={font=\large}, % 刻度标签字体大小
    ]
    % 绘制正弦曲线
    \addplot[
        domain=0:6.2832, % 绘制范围0到2π
        samples=100, % 采样点数量保证曲线平滑
        thick, % 曲线粗细
        blue, % 曲线颜色
    ] {sin(x)};
    
    % 标注振幅
    \draw[red, dashed] (axis cs:1.5708,0) -- (axis cs:1.5708,1);
    \node[red, above right] at (axis cs:1.5708,0.5) {振幅 $1$};
    
    % 标注周期
    \draw[green, dashed] (axis cs:0,-0.2) -- (axis cs:6.2832,-0.2);
    \node[green, below] at (axis cs:3.1416,-0.2) {周期 $2\pi$};
    
    % 标注原点
    \node[below left] at (axis cs:0,0) {$O$};
    
    % 标记关键顶点
    \fill[black] (axis cs:1.5708,1) circle (2pt);
    \fill[black] (axis cs:4.7124,-1) circle (2pt);
    \fill[black] (axis cs:3.1416,0) circle (2pt);
\end{axis}
\end{tikzpicture}
\end{document}

代码说明:

  • 采用standalone文档类,便于单独导出高清图像;
  • 指定pgfplots兼容版本,避免不同版本的语法差异;
  • 坐标轴设置为中心交汇样式,刻度标签使用标准数学符号;
  • 正弦曲线通过domain指定绘制范围,samples参数保证曲线平滑度;
  • 用红色虚线标注振幅,绿色虚线标注周期,关键坐标点用实心圆点突出;
  • 网格设置为灰色虚线,辅助读取坐标值。

内容的提问来源于stack exchange,提问作者prasobh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 03:51:35