3
$\begingroup$

I would like to make a statistical graph (chart) from data in the format {x-value, mean value, standard deviation} as in:

{{10, 10.73, 0.72}, {20, 14.10, 0.49}, {30, 13.96, 0.49}, {40, 13.43, 0.51}}

I would like the graph to resemble a BoxWhiskerChart, where at each x value the mean is plotted and thin bars extending above and below the mean by a distance equal to the standard deviation. However, BoxWhiskerChart requires the data at each x value to be an entire data set (of multiple points), not the statistical summary. I have merely the mean and standard deviation.

I can kludge drawing lines by computing ranges and such, as follows:

Show[ListPlot[data[[All, {1, 2}]],
  Joined -> True,
  PlotRange -> {0, Automatic}],
 Epilog -> 
  Table[{Red, 
    Line[{{data[[i, 1]], data[[i, 2]] - data[[i, 3]]}, {data[[i, 1]], 
       data[[i, 2]] + data[[i, 3]]}}]}, {i, Length[data]}]]

enter image description here

However, because I have lots of data, and ultimately wish to place several such plots on a single graph (of different colors), I was hoping there was a way to modify BoxWhiskerChart (or related chart) so I can exploit the internal functions and styling.

$\endgroup$
4
$\begingroup$
list = {{10, 10.73, 0.72}, {20, 14.10, 0.49}, {30, 13.96, 0.49}, {40, 13.43, 0.51}};

ListLinePlot[ {#1, Around[#2, #3]} & @@@ list ]

plot with error bars


For previous versions (Around is new in 12.0):

Needs["ErrorBarPlots`"]
Show[ErrorListPlot[list], PlotRange -> All]

errorlistplot

ErrorListPlot takes the option Joined -> True, just like ListPlot, if you want the connecting lines as well. The weird Show[.., PlotRange -> All] is there to avoid clipping of the error bars.

$\endgroup$
  • $\begingroup$ Wow... I had never seen that function. Thanks so much! ($\checkmark$) $\endgroup$ – David G. Stork May 24 '20 at 18:56
  • $\begingroup$ @DavidG.Stork I think it's new in 12.0. Pretty handy, finally there is a simple a way of generating plots with proper error bar in MMA :-) $\endgroup$ – MarcoB May 24 '20 at 18:57
  • $\begingroup$ Ugh... I "accepted" too soon. I am running v. 11.3 and it doesn't work. Any suggestion for v. 11.3? $\endgroup$ – David G. Stork May 24 '20 at 18:59
  • $\begingroup$ @DavidG.Stork Yep, see edit. $\endgroup$ – MarcoB May 24 '20 at 19:03
  • $\begingroup$ Got it. Works. Thanks so much. (Previous acceptance now fully justified!) $\endgroup$ – David G. Stork May 24 '20 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.