'Change matplotlib boxplot quartiles
I'm making a boxplot of data with a NaN value using matplotlib, and I've encountered multiple issues with the quartiles and median. I had to manually set the median with the usermedians argument since the automatically calculated median returned a NaN, and I've discovered that Q1 and Q3 are also completely wrong compared to my manual calculations. How can I change the values for the quartiles so that the top and bottom of the box are correct?
Edit: I was asked to provide some sample data and code, so that is below! The data in question comes from a Pandas dataframe.
df = pd.DataFrame([1.67, 3.94, 3.83, 2.43, 0.75, 5.16, 3.49, 0.84, 4.12, 4.08, 14.72,
0.5, 6.21, 2.28, 3.6, 7.17, 2.32, 3.94, 1.38, 5.47, 'T', 0.78,
5.43, 1.43, 0.75, 4.66, 3.8, 2.54, 1.49, 3.58, 1.13, 3.04, 1.21,
0.48, 1.35, 5.57, 2.78, 3.95, 5.28, 6, 6.56, 1.15],columns=['Oct'])
df_masked = df.mask( df == 'T')
fig = plt.figure()
ax = fig.add_subplot(111)
ax2 = ax.boxplot(df_masked['Oct'], labels=['Oct'], widths=0.5, patch_artist=True, usermedians=[df_masked['Oct'].median()])
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
