误差线不根据 y 轴缩放

误差线不根据 y 轴缩放

我正在为我的论文制作一个带误差线的图表。但是误差线的值似乎没有根据 y 轴缩放,因此大小完全不对。我没有使用过 LaTeX,所以如果有人能帮忙我将非常感激。

我的 MWE:

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    width  = 0.85*\textwidth,
    height = 8cm,
    major x tick style = transparent,
    ybar=2*\pgflinewidth,
    bar width=19pt,
    ymajorgrids = true,
    ylabel = {\% of null tokens},
    symbolic x coords={Subject,Object,Copula},
    xtick = data,
    ytick={0.00, 0.2, 0.4, 0.6, 0.8, 1},
    enlarge x limits=0.25,
    ymin=0,
    ymax=1,
    legend cell align=left,
    legend style={
            at={(0.97,0.95)},
            anchor=north east,
            column sep=1ex
    }
]
    \addplot+[error bars/.cd,y dir=both,y explicit]
        coordinates {
        (Subject, 0.318) +- (0.3035, 0.3322)
        (Object, 0.238) +- (0.2051, 0.2748)
        (Copula, 0.12) +- (0.09, 0.14)
        };

    \addplot+[error bars/.cd,y dir=both,y explicit]
         coordinates {
         (Subject, 0.315) +- (0.2837, 0.3485)
         (Object, 0.130) +- (0.0854, 0.1878)
         (Copula, 0.084) +- (0.0511, 0.1276)
         };
    \legend{Gen 1, Gen 2}
\end{axis}
\end{tikzpicture}
\end{document}

答案1

欢迎使用 TeX.SE!将文档完成为一个最小工作示例后,添加\pgfplotsset{compat=1.16}和替换ybar=2*\pgflinewidthybar=\pgflinewidth提高准确性,误差线看起来非常正确。当然,这假设您提供的误差值为绝对错误值,因为您已经使用了y explicit

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    width  = 0.85*\textwidth,
    height = 8cm,
    major x tick style = transparent,
    ybar=\pgflinewidth,
    bar width=19pt,
    ymajorgrids = true,
    ylabel = {\% of null tokens},
    symbolic x coords={Subject, Object, Copula},
    xtick = data,
    ytick={0.0, 0.2, 0.4, 0.6, 0.8, 1},
    enlarge x limits=0.25,
    ymin=0,
    ymax=1,
    legend cell align=left,
    legend style={
            at={(0.97,0.95)},
            anchor=north east,
    }
]
    \addplot+[error bars/.cd, y dir=both, y explicit]
        coordinates {
        (Subject, 0.318) +- (0.3035, 0.3322)
        (Object, 0.238) +- (0.2051, 0.2748)
        (Copula, 0.12) +- (0.09, 0.14)
        };

    \addplot+[error bars/.cd, y dir=both, y explicit]
         coordinates {
         (Subject, 0.315) +- (0.2837, 0.3485)
         (Object, 0.130) +- (0.0854, 0.1878)
         (Copula, 0.084) +- (0.0511, 0.1276)
         };
    \legend{Gen 1, Gen 2}
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

如果您希望将错误值解释为相对的y explicit relative代替y explicit

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    width  = 0.85*\textwidth,
    height = 8cm,
    major x tick style = transparent,
    ybar=\pgflinewidth,
    bar width=19pt,
    ymajorgrids = true,
    ylabel = {\% of null tokens},
    symbolic x coords={Subject, Object, Copula},
    xtick = data,
    ytick={0.0, 0.2, 0.4, 0.6, 0.8, 1},
    enlarge x limits=0.25,
    ymin=0,
    ymax=1,
    legend cell align=left,
    legend style={
            at={(0.97,0.95)},
            anchor=north east,
    }
]
    \addplot+[error bars/.cd, y dir=both, y explicit relative]
        coordinates {
        (Subject, 0.318) +- (0.3035, 0.3322)
        (Object, 0.238) +- (0.2051, 0.2748)
        (Copula, 0.12) +- (0.09, 0.14)
        };

    \addplot+[error bars/.cd, y dir=both, y explicit relative]
         coordinates {
         (Subject, 0.315) +- (0.2837, 0.3485)
         (Object, 0.130) +- (0.0854, 0.1878)
         (Copula, 0.084) +- (0.0511, 0.1276)
         };
    \legend{Gen 1, Gen 2}
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

下次请提供一个完整的示例,以 开头\documentclass并以 结尾\end{document}

相关内容