使用坐标 o 将误差线添加到 pgfplot

使用坐标 o 将误差线添加到 pgfplot

我刚刚开始使用pgfplots,对 Latex 总体上还不是很熟悉。我有以下内容,虽然还不够完善(例如,我需要扩大宽度以适应图例),但正在逐步完善。

我想知道的是,error bar当通过像这样的直接坐标对绘制数据集时,如何将 s 添加到其中一个数据集?还是我需要创建一个表格?

\documentclass{article}

\usepackage{caption}
\usepackage{pgfplots}

\begin{document}

\begin{figure}
\centering
\label{ScoreVersusSize}
    \begin{tikzpicture}
        \begin{axis}[
                xlabel=Model Size,
                ylabel=Avg Project Score]
                \addplot coordinates {
                    (3, 0.608)
                    (4, 0.621)
                    (5, 0.589)
                    (6, 0.569)
                    (7, 0.549)
                    (8, 0.542)
                    (9, 0.558)
                    };
                \addlegendentry{Model Specific Score}
                \addplot coordinates {
                    (3, 0.577)
                    (4, 0.577)
                    (5, 0.577)
                    (6, 0.577)
                    (7, 0.577)
                    (8, 0.577)
                    (9, 0.577)
                    };
                    \addlegendentry{Aggregate Average Score}
        \end{axis}
    \end{tikzpicture}
    \caption{Average Score versus Model Size}
\end{figure}

\end{document}

答案1

步骤 1——阅读手册!

\documentclass{article}

\usepackage{caption}
\usepackage{pgfplots}

\begin{document}

\begin{figure}
\centering
\label{ScoreVersusSize}
    \begin{tikzpicture}
        \begin{axis}[
                xlabel=Model Size,
                ylabel=Avg Project Score]
            \addplot+[error bars/.cd,
                       y dir=both, y explicit]
                    coordinates {
                    (3, 0.608)  +- (0.0495, 0.0495)
                    (4, 0.621)  +- (0.0406, 0.0406)
                    (5, 0.589)  +- (0.0410, 0.0410)
                    (6, 0.569)  +- (0.0381, 0.0381)
                    (7, 0.549)  +- (0.0354, 0.0354)
                    (8, 0.542)  +- (0.0341, 0.0341)
                    (9, 0.558)  +- (0.0331, 0.0331)
                    };
                \addlegendentry{Model Specific Score}
                \addplot[mark = none, red] coordinates {
                    (3, 0.577)
                    (4, 0.577)
                    (5, 0.577)
                    (6, 0.577)
                    (7, 0.577)
                    (8, 0.577)
                    (9, 0.577)
                    };
                    \addlegendentry{Aggregate Average Score}
        \end{axis}
    \end{tikzpicture}
    \caption{Average Score versus Model Size}
\end{figure}

相关内容