I am using matplotlib to generate a boxplot. In order to create the plot, the boxplot class is internally calculating the means, standard deviations and medians. How can I extract these numerical values?
The boxplot returns a dictionary with the objects within it. Included in this is a list of Line2D objects under the key 'medians', one for each series in the data array.
box = ax.boxplot(data, showmeans=True)
box
>>>{'whiskers': [<matplotlib.lines.Line2D at 0x2580149d0d0>,
<matplotlib.lines.Line2D at 0x2580149d460>,
<matplotlib.lines.Line2D at 0x258014a7a00>,
<matplotlib.lines.Line2D at 0x258014a7d90>, ...etc.... ],
'caps': [<matplotlib.lines.Line2D at 0x2580149d7f0>,
<matplotlib.lines.Line2D at 0x2580149db80>,
<matplotlib.lines.Line2D at 0x2580170a160>,
<matplotlib.lines.Line2D at 0x2580170a4f0>, ...etc.... ],
'boxes': [<matplotlib.lines.Line2D at 0x2580410fd00>,
<matplotlib.lines.Line2D at 0x258014a7670>,
<matplotlib.lines.Line2D at 0x2580170afa0>,
<matplotlib.lines.Line2D at 0x25801708910>, ...etc.... ],
'medians': [<matplotlib.lines.Line2D at 0x2580149df10>,
<matplotlib.lines.Line2D at 0x2580170a880>,
<matplotlib.lines.Line2D at 0x258017081f0>,
<matplotlib.lines.Line2D at 0x25802263b20>, ...etc.... ],
'fliers': [],
'means': [<matplotlib.lines.Line2D at 0x258014a72e0>,
<matplotlib.lines.Line2D at 0x2580170ac10>,
<matplotlib.lines.Line2D at 0x25801708580>,
<matplotlib.lines.Line2D at 0x25802263eb0>, ...etc.... ],}
Is there some way I can get the median values (and also means, standard deviations) back from the plot object itself? This could be useful in some cases, to compare it to the values I calculated from the data myself.