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:
Group the data points for each month using TimeSeriesWindow (define ends of the months first):
Calculate the mean for each month:
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:
Calculate the standard error of the high temperatures for each month:
Next, define a function that will let you put error bars on a bar chart:
This function takes its data points as data->error. Here, the means and associated standard errors are put into this form:
Before making the chart, create and style labels for each month:
Use BarChart to make the chart:
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 {data,error}. Here, the data is put into this form:
Set up tick labels to use with ErrorListPlot:
Plot the data with ErrorListPlot: