tikzpicture 曲线部分显示

tikzpicture 曲线部分显示

我想在同一张图中绘制理论图和一些实验测量值。pgfplot 仅显示其中的一部分(见图)。

以下是我整理的内容:

\begin{tikzpicture}
\begin{axis}
[
     xlabel={angle $\alpha$ (\degree)},
    ylabel={power (mW)},
        ymajorgrids=true,
        xmajorgrids=true,
    grid style=dashed,
]
\addplot [color=red]{ 100 * ( cos( x -14) )^2};
%\addlegendentry{model}
\addplot [mark=.,only marks, error bars/.cd,
    x dir=both,x fixed=1,
    y dir=both,y explicit]
coordinates {
(14,    98.5)
(15,    98.1) 
(20,    93.9) 
(25,    84.8) 
(30,    71.69) 
(35,    55.1)
(40,    38.8) 
(45,    20.4) 
(50,    10.2) 
(55,    1.7) 
(59,    0) 
(60,    0.1) 
};
%\addlegendentry{experimental data}
\end{axis}
\end{tikzpicture}

答案1

正如前面提到的在问题下方评论您需要添加domain=<xmin>:<xmax>axis选项\addplot才能获得所需的结果。

% used PGFPlots v1.15
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{
        compat=1.3,
    }
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        % (better practice is to write the degree symbol directly at the ticklabels)
        xticklabel=$\pgfmathprintnumber{\tick}^\circ$,
        xlabel={angle $\alpha$},
        ylabel={power (mW)},
        ymajorgrids=true,
        xmajorgrids=true,
        grid style=dashed,
    ]
        \addplot [
            color=red,
            domain=0:60,        % <-- added
        ] {100*cos(x-14)^2};

        \addplot [
            mark=.,
            only marks,
            error bars/.cd,
                x dir=both,x fixed=1,
%                % (there are not given any error values)
%                y dir=both,y explicit,
        ] coordinates {
            (14, 98.5)
            (15, 98.1)
            (20, 93.9)
            (25, 84.8)
            (30, 71.69)
            (35, 55.1)
            (40, 38.8)
            (45, 20.4)
            (50, 10.2)
            (55, 1.7)
            (59, 0)
            (60, 0.1)
        };
    \end{axis}
\end{tikzpicture}
\end{document}

该图显示了上述代码的结果

相关内容