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):
Use GatherBy to group the data by month:
Get only the data points for each month:
Calculate the mean for each month:
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:
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:
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 . Here, the data is put into this form:
Set up tick labels to use with ErrorListPlot:
Plot the data with ErrorListPlot: