MATHEMATICA HOW TO

# 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. Mathematica 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):

Use GatherBy to group the data by month:

Get only the data points for each month:

 Out[8]=

Calculate the mean for each month:

 Out[9]=

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:

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

 Out[11]=

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

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

 Out[13]=

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

Use BarChart to make the chart:

 Out[15]=

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:

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

 Out[21]=

Set up tick labels to use with ErrorListPlot:

Plot the data with ErrorListPlot:

 Out[23]=

## See AlsoSee Also

New to Mathematica? Find your learning path »
Have a question? Ask support »