When plotting a boxplot with python matplotblib, the lines halfway the plot is the median of the distribution.
Is there a possibility to instead have the line at the average. Or to plot it next to it in a different style.
Also, because it is common for the line to be the median, will it really confuse my readers if I make it the average (off course I will add a note what the middle line is)?
Answer
This code makes the boxplots then places a circle marking the mean for each box. You can use a different symbol by specifying the marker argument in the call to scatter
.
import numpy as np
import pylab
# 3 boxes
data = [[np.random.rand(100)] for i in range(3)]
pylab.boxplot(data)
# mark the mean
means = [np.mean(x) for x in data]
pylab.scatter([1, 2, 3], means)
Attribution
Source : Link , Question Author : Peter Smit , Answer Author : ars