Boxplots now support a label parameter to create legend entries. Legend labels can be
passed as a list of strings to label multiple boxes in a single call:
Axes.boxplot
np.random.seed(19680801)fruit_weights=[np.random.normal(130,10,size=100),np.random.normal(125,20,size=100),np.random.normal(120,30,size=100),]labels=['peaches','oranges','tomatoes']colors=['peachpuff','orange','tomato']fig,ax=plt.subplots()ax.set_ylabel('fruit weight (g)')bplot=ax.boxplot(fruit_weights,patch_artist=True,# fill with colorlabel=labels)# fill with colorsforpatch,colorinzip(bplot['boxes'],colors):patch.set_facecolor(color)ax.set_xticks([])ax.legend()
Percent sign in pie labels auto-escaped with usetex=True
It is common, with Axes.pie, to specify labels that include a percent sign (%),
which denotes a comment for LaTeX. When enabling LaTeX with rcParams["text.usetex"] (default: False) or passing
textprops={"usetex":True}, this used to cause the percent sign to disappear.
Now, the percent sign is automatically escaped (by adding a preceding backslash) so that
it appears regardless of the usetex setting. If you have pre-escaped the percent
sign, this will be detected, and remain as is.
hatch parameter for stackplot
The stackplothatch parameter now accepts a list of strings describing
hatching styles that will be applied sequentially to the layers in the stack:
Setting the parameter side to 'low' or 'high' allows to only plot one half of the
Axes.violinplot.
# Fake data with reproducible random state.np.random.seed(19680801)data=np.random.normal(0,8,size=100)fig,ax=plt.subplots()ax.violinplot(data,[0],showmeans=True,showextrema=True)ax.violinplot(data,[1],showmeans=True,showextrema=True,side='low')ax.violinplot(data,[2],showmeans=True,showextrema=True,side='high')ax.set_title('Violin Sides Example')ax.set_xticks([0,1,2],['Default','side="low"','side="high"'])ax.set_yticklabels([])
Subplot axes titles can be misaligned vertically if tick labels or xlabels are placed at
the top of one subplot. The new align_titles method on the Figure class
will now align the titles vertically.
Previously, setting the zorder of a subfigure had no effect, and those were plotted on
top of any figure-level artists (i.e for example on top of fig-level legends). Now,
subfigures behave like any other artists, and their zorder can be controlled, with
default a zorder of 0.
The documentation is updated to take information directly from the parser. This means
that (almost) all supported symbols, operators, etc. are shown at Writing mathematical expressions.
mathtext spacing corrections
As consequence of the updated documentation, the spacing on a number of relational and
operator symbols were correctly classified and therefore will be spaced properly.
Widget Improvements
Check and Radio Button widgets support clearing
The CheckButtons and RadioButtons widgets now support clearing their state by
calling their .clear method. Note that it is not possible to have no selected radio
buttons, so the selected option at construction time is selected.
3D plotting improvements
Setting 3D axis limits now set the limits exactly
Previously, setting the limits of a 3D axis would always add a small margin to the
limits. Limits are now set exactly by default. The newly introduced rcparam
axes3d.automargin can be used to revert to the old behavior where margin is
automatically added.
fig,axs=plt.subplots(1,2,subplot_kw={'projection':'3d'})plt.rcParams['axes3d.automargin']=Trueaxs[0].set(xlim=(0,1),ylim=(0,1),zlim=(0,1),title='Old Behavior')plt.rcParams['axes3d.automargin']=False# the default in 3.9.0axs[1].set(xlim=(0,1),ylim=(0,1),zlim=(0,1),title='New Behavior')
New BackendRegistry class is the single source of
truth for available backends. The singleton instance is
matplotlib.backends.backend_registry. It is used internally by Matplotlib, and also
IPython (and therefore Jupyter) starting with IPython 8.24.0.
There are three sources of backends: built-in (source code is within the Matplotlib
repository), explicit module://some.backend syntax (backend is obtained by loading
the module), or via an entry point (self-registering backend in an external package).