pgfplots:带有置信区间的条形图(误差)

pgfplots:带有置信区间的条形图(误差)

我想在条形图中放置一个置信区间(误差线),但我尝试了 += 和 -=,但没有作用。

以下是代码:

    \begin{tikzpicture}
    \begin{axis}[
    width  = 0.50*\textwidth,
    height = 8cm,
    major x tick style = transparent,
    ybar=2*\pgflinewidth,
    bar width=25pt,
    ymajorgrids = true,
    symbolic x coords={A,B},
    xtick = data,
    scaled y ticks = false,
    enlarge x limits=0.50,
    ymin=0,
    legend cell align=left,
    legend style={at={(0.5,-0.12)},anchor=north}
]
    \addplot[style={fill=white}]
        coordinates {
        (A, 2.98)
        (B,4.23)};

    \addplot[style={fill=black}]
         coordinates {
         (A,4.33)
         (B,3.82)};

    \legend{Red Graph, Blue Graph}
\end{axis}
\end{tikzpicture}

答案1

你必须error bars使用类似的东西来启用

error bars/.cd, y dir=both, y explicit

作为情节选项。

例子:

  \documentclass{standalone}
  \usepackage{pgfplots}
  \pgfplotsset{compat=1.12}
  \begin{document}

      \begin{tikzpicture}
      \begin{axis}[
      width  = 0.50*\textwidth,
      height = 8cm,
      major x tick style = transparent,
      ybar=2*\pgflinewidth,
      bar width=25pt,
      ymajorgrids = true,
      symbolic x coords={A,B},
      xtick = data,
      scaled y ticks = false,
      enlarge x limits=0.50,
      ymin=0,
      legend cell align=left,
      legend style={at={(0.5,-0.12)},anchor=north},
  ]
      \addplot[style={fill=white},error bars/.cd, y dir=both, y explicit]
          coordinates {
          (A, 2.98) += (0,0.2) -= (0,0.1)
          (B,4.23) += (0,0.2) -= (0,0.1)};

      \addplot[style={fill=black},error bars/.cd, y dir=both, y explicit,error bar style=red]
           coordinates {
           (A,4.33) += (0,0.2) -= (0,0.1)
           (B,3.82) += (0,0.5) -= (0,0.2)};

      \legend{White Graph, Black Graph}
  \end{axis}
  \end{tikzpicture}
  \end{document}

在此处输入图片描述

相关内容