Changing the mustache tips in the boxplot matplotlib function

I understand that the mustache ends in the graph function of the matplotlib field extend to a maximum value below 75% + 1.5 IQR and a minimum value above 25% - 1.5 IQR. I would like to modify it to represent the maximum and minimum data values ​​or the 5th and 95th quartile of data. Is it possible to do this?

+8
python matplotlib
source share
2 answers

To make the mustache appear with minimum and maximum data values, set the whis parameter to an arbitrarily large number. In other words: boxplots = ax.boxplot(myData, whis=np.inf) .

whis kwarg - interquartile range scaling factor. The whiskers extend to external data points within whis * IQR of the quartiles.

Now that v1.4 is missing:

In matplotlib v1.4 you can say: boxplots = ax.boxplot(myData, whis=[5, 95]) set the mustache on the 5th and 95th percentiles. Similarly, you can say boxplots = ax.boxplot(myData, whis='range') to set the mustache in minutes and max.

Note. Perhaps you could change the artists contained in the boxplots dictionary returned by the ax.boxplot method, but this seems like a huge hassle

+14
source share

Set the boxplot whisk = 0 option to hide the built-in whiskers. Then create a custom mustache that shows data from 5% to 95%.

 #create markings that represent the ends of whiskers low=data.quantile(0.05) high=data.quantile(0.95) plt.scatter(range(1,len(low)+1),low,marker='_') plt.scatter(range(1,len(low)+1),high,marker='_') #connects low and high markers with a line plt.vlines(range(1,len(low)+1),low,high) 

This should create vertical lines with the whiskers marked behind the boxes by 5% at 95%.

0
source share

All Articles