The 'ellipse' option for boxstyle can now be used to create annotations
with an elliptical outline. It can be used as a closed curve shape for
longer texts instead of the 'circle' boxstyle which can get quite big.
The order of legend entries can now be reversed by passing reverse=True to
legend.
pcolormesh accepts RGB(A) colors
The pcolormesh method can now handle explicit colors
specified with RGB(A) values. To specify colors, the array must be 3D
with a shape of (M,N,[3,4]).
View current appearance settings for ticks, tick labels, and gridlines
The new get_tick_params method can be used to
retrieve the appearance settings that will be applied to any
additional ticks, tick labels, and gridlines added to the plot:
Style files can be imported from third-party packages
Third-party packages can now distribute style files that are globally available
as follows. Assume that a package is importable as importmypackage, with
a mypackage/__init__.py module. Then a mypackage/presentation.mplstyle
style sheet can be used as plt.style.use("mypackage.presentation").
The implementation does not actually import mypackage, making this process
safe against possible import-time side effects. Subpackages (e.g.
dotted.package.name) are also supported.
Improvements to 3D Plotting
3D plot pan and zoom buttons
The pan and zoom buttons in the toolbar of 3D plots are now enabled.
Unselect both to rotate the plot. When the zoom button is pressed,
zoom in by using the left mouse button to draw a bounding box, and
out by using the right mouse button to draw the box. When zooming a
3D plot, the current view aspect ratios are kept fixed.
adjustable keyword argument for setting equal aspect ratios in 3D
While setting equal aspect ratios for 3D plots, users can choose to modify
either the data limits or the bounding box in parity with 2D Axes.
importmatplotlib.pyplotaspltimportnumpyasnpfromitertoolsimportcombinations,productaspects=('auto','equal','equalxy','equalyz','equalxz')fig,axs=plt.subplots(1,len(aspects),subplot_kw={'projection':'3d'},figsize=(12,6))# Draw rectangular cuboid with side lengths [4, 3, 5]r=[0,1]scale=np.array([4,3,5])pts=combinations(np.array(list(product(r,r,r))),2)forstart,endinpts:ifnp.sum(np.abs(start-end))==r[1]-r[0]:foraxinaxs:ax.plot3D(*zip(start*scale,end*scale),color='C0')# Set the aspect ratiosfori,axinenumerate(axs):ax.set_aspect(aspects[i],adjustable='datalim')# Alternatively: ax.set_aspect(aspects[i], adjustable='box')# which will change the box aspect ratio instead of axis data limits.ax.set_title(f"set_aspect('{aspects[i]}')")plt.show()
It is now possible to shade a Poly3DCollection. This is useful if the
polygons are obtained from e.g. a 3D model.
importnumpyasnpimportmatplotlib.pyplotaspltfrommpl_toolkits.mplot3d.art3dimportPoly3DCollection# Define 3D shapeblock=
rcParam for 3D pane color
The rcParams rcParams["axes3d.xaxis.panecolor"] (default: (0.95,0.95,0.95,0.5)), rcParams["axes3d.yaxis.panecolor"] (default: (0.9,0.9,0.9,0.5)),
rcParams["axes3d.zaxis.panecolor"] (default: (0.925,0.925,0.925,0.5)) can be used to change the color of the background
panes in 3D plots. Note that it is often beneficial to give them slightly
different shades to obtain a "3D effect" and to make them slightly transparent
(alpha < 1).
Figure and Axes Layout
colorbar now has a location keyword argument
The colorbar method now supports a location keyword argument to more
easily position the color bar. This is useful when providing your own inset
axes using the cax keyword argument and behaves similar to the case where
axes are not provided (where the location keyword is passed through).
orientation and ticklocation are no longer required as they are
determined by location. ticklocation can still be provided if the
automatic setting is not preferred. (orientation can also be provided but
must be compatible with the location.)
Figure legends can be placed outside figures using constrained_layout
Constrained layout will make space for Figure legends if they are specified
by a loc keyword argument that starts with the string "outside". The
codes are unique from axes codes, in that "outside upper right" will
make room at the top of the figure for the legend, whereas
"outside right upper" will make room on the right-hand side of the figure.
See Legend guide for details.
Additional custom styling of button widgets may be achieved via the
label_props and radio_props arguments to RadioButtons; and the
label_props, frame_props, and check_props arguments to CheckButtons.
The Button, CheckButtons, and RadioButtons widgets now support
blitting for faster rendering, on backends that support it, by passing
useblit=True to the constructor. Blitting is enabled by default on
supported backends.
Other Improvements
Source links can be shown or hidden for each Sphinx plot directive
The Sphinx plot directive
(..plot::) now supports a :show-source-link: option to show or hide
the link to the source code for each plot. The default is set using the
plot_html_show_source_link variable in conf.py (which
defaults to True).
Figure hooks
The new rcParams["figure.hooks"] (default: []) provides a mechanism to register
arbitrary customizations on pyplot figures; it is a list of
"dotted.module.name:dotted.callable.name" strings specifying functions
that are called on each figure created by pyplot.figure; these
functions can e.g. attach callbacks or modify the toolbar. See
mplcvd -- an example of figure hook for an example of toolbar customization.