Repository navigation
Box Plots notebook: pandas .plot(kind='box', vert=False) will break on matplotlib 3.13 #9
Description
1. pandas .plot(kind='box', vert=False)
File: 2_Advanced/18_Matplotlib_Box_Plots.ipynb
Two cells use pandas plotting with the vert argument:
df_DA_US['salary_year_avg'].plot(kind='box', vert=False)df_DA_US['salary_year_avg'].plot(kind='box', ax=ax[1], vert=False)pandas passes vert straight through to matplotlib, and matplotlib deprecated it in 3.11 in favor of orientation:
MatplotlibDeprecationWarning: vert: bool was deprecated in Matplotlib 3.11 and will be removed in 3.13. Use orientation: {'vertical', 'horizontal'} instead.
Why this isn't fixed yet: pandas (as of 3.0.x, and still on main) keys its box plot tick labels off vert, and doesn't recognize orientation. Passing orientation='horizontal' through pandas renders the plot but mislabels the ticks and throws a UserWarning. So the cells stay on vert=False for now; they work, just with a warning.
When to revisit: whichever comes first:
- matplotlib 3.13 is released (
vertremoved), or - pandas adds
orientationsupport for box plots (watchpandas/plotting/_matplotlib/boxplot.py, theorientationproperty currently readsself.kwds.get("vert", True))
Fix options at that point:
- If pandas supports it: swap
vert=False→orientation='horizontal'in both cells. - If pandas still doesn't: switch those two cells to matplotlib directly, which the notebook already notes as an alternative:
The second cell would become
plt.boxplot(df_DA_US['salary_year_avg'], orientation='horizontal')
ax[1].boxplot(df_DA_US['salary_year_avg'], orientation='horizontal').
Also update the markdown syntax line in the same notebook (boxplot(column=[...], by=None, vert=False)) to match.
2. seaborn sns.boxplot() (nothing to change in our code, but same clock)
seaborn 0.13.2 (current release) passes vert to matplotlib internally, so every sns.boxplot(...) call also triggers the deprecation warning on matplotlib 3.11 and will break on 3.13 until seaborn ships a fix. Affected in this course:
2_Advanced/20_Seaborn_Intro.ipynb:sns.boxplot(data=df_US, x='salary_year_avg', y='job_title_short')3_Project/4_Salary_Analysis.ipynb:sns.boxplot(data=df_US_top6, x='salary_year_avg', y='job_title_short', order=job_order)- Kajabi problem 2.20.3 solution (same
sns.boxplotcall)
Nothing to edit on our side; the fix is upgrading seaborn once a release newer than 0.13.2 handles orientation. If seaborn hasn't shipped that by the time matplotlib 3.13 is out, the workaround for students is pinning matplotlib (pip install "matplotlib<3.13") or using plt.boxplot(..., orientation='horizontal') directly for those three plots.
Related: the plt.boxplot(... labels=..., vert=False) cells in this notebook and 20_Seaborn_Intro.ipynb were already updated to tick_labels / orientation (commit efeea59). Colab currently ships matplotlib 3.10.0 / pandas 2.2.3 / seaborn 0.13.2, where everything here still runs. A full run of every lesson notebook and problem solution on matplotlib 3.11.2 found no other matplotlib breakage.
Activity