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 in the form of TimeSeries:

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

Group the data points for each month using TimeSeriesWindow (define ends of the months first):

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

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 given as TimeSeries. 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 data->error. 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 {data,error}. 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]=

Tutorials

See Also

StandardDeviation  Sqrt  Length  BarChart  ErrorListPlot