How to | Add Error Bars to Charts and Plots

Plots of data based on measurements often have vertical lines or intervals centered at the points to indicate the associated error estimates. The Wolfram Language lets you add such error bars to charts and plots in two different ways.

The following steps calculate and then plot the mean high temperatures in St. Louis for each month in 2009.

Use WeatherData to import the daily high temperatures in St. Louis from 2009 (the large output is suppressed with "" at the end of the command):

In[1]:=
Click for copyable input

Use GatherBy to group the data by month:

In[2]:=
Click for copyable input

Get only the data points for each month:

In[3]:=
Click for copyable input
Out[3]=

Calculate the mean for each month:

In[4]:=
Click for copyable input
Out[4]=

Define a function that calculates the standard error of a dataset. Here, the standard error is the standard deviation divided by the square root of the number of observations in the dataset:

In[5]:=
Click for copyable input

Calculate the standard error of the high temperatures for each month:

In[6]:=
Click for copyable input
Out[6]=

Next, define a function that will let you put error bars on a bar chart:

In[7]:=
Click for copyable input

This function takes its data points as . Here, the means and associated standard errors are put into this form:

In[8]:=
Click for copyable input
Out[8]=

Before making the chart, create and style labels for each month:

In[9]:=
Click for copyable input

Use BarChart to make the chart:

In[10]:=
Click for copyable input
Out[10]=

You can also show this data and associated errors in a plot where each mean is joined by a line.

To do this, first load the ErrorBar Plotting Package:

In[11]:=
Click for copyable input

ErrorListPlot, which is part of this package, takes its data in a list as . Here, the data is put into this form:

In[12]:=
Click for copyable input
Out[12]=

Set up tick labels to use with ErrorListPlot:

In[13]:=
Click for copyable input

Plot the data with ErrorListPlot:

In[14]:=
Click for copyable input
Out[14]=