Matplotlib now provides first-party PEP484 style type hints files for most public APIs.
While still considered provisional and subject to change (and sometimes we are not
quite able to fully specify what we would like to), they should provide a reasonable
basis to type check many common usage patterns, as well as integrating with many
editors/IDEs.
Plotting and Annotation improvements
Support customizing antialiasing for text and annotation
matplotlib.pyplot.annotate() and matplotlib.pyplot.text() now support parameter antialiased.
When antialiased is set to , antialiasing will be applied to the text.
When is set to , antialiasing will not be applied to the text.
When is not specified, antialiasing will be set by (default: ) at the creation time of and object.
Examples:
mpl.text.Text(.5,.5,"foo\nbar",antialiased=True)plt.text(0.5,0.5,'6 inches x 2 inches',antialiased=True)ax.annotate('local max',xy=(2,1),xytext=(3,1.5),antialiased=False)
If the text contains math expression, antialiased applies to the whole text.
Examples:
# no part will be antialiased for the text belowplt.text(0.5,0.25,r"$I'm \sqrt{x}$",antialiased=False)
Also note that antialiasing for tick labels will be set with rcParams["text.antialiased"] (default: True) when they are created (usually when a Figure is created) and cannot be changed afterwards.
Furthermore, with this new feature, you may want to make sure that you are creating and saving/showing the figure under the same context:
# previously this was a no-op, now it is what workswithrccontext(text.antialiased=False):fig,ax=plt.subplots()ax.annotate('local max',xy=(2,1),xytext=(3,1.5))fig.savefig('/tmp/test.png')# previously this had an effect, now this is a no-opfig,ax=plt.subplots()ax.annotate('local max',xy=(2,1),xytext=(3,1.5))withrccontext(text.antialiased=False):fig.savefig('/tmp/test.png')
rcParams for AutoMinorLocator divisions
The rcParams rcParams["xtick.minor.ndivs"] (default: 'auto') and rcParams["ytick.minor.ndivs"] (default: 'auto') have been
added to enable setting the default number of divisions; if set to auto,
the number of divisions will be chosen by the distance between major ticks.
Axline setters and getters
The returned object from axes.Axes.axline now supports getter and setter
methods for its xy1, xy2 and slope attributes:
These methods return the strings set by Figure.suptitle(), Figure.supxlabel()
and Figure.supylabel() respectively.
Ellipse.get_vertices(), Ellipse.get_co_vertices()
These methods return the coordinates of ellipse vertices of
major and minor axis. Additionally, an example gallery demo is added which
shows how to add an arrow to an ellipse showing a clockwise or counter-clockwise
rotation of the ellipse. To place the arrow exactly on the ellipse,
the coordinates of the vertices are used.
Remove inner ticks in label_outer()
Up to now, label_outer() has only removed the ticklabels. The ticks lines
were left visible. This is now configurable through a new parameter
label_outer(remove_inner_ticks=True).
The shadow parameter of legends now accepts dicts in addition to booleans.
Dictionaries can contain any keywords for patches.Patch.
For example, this allows one to set the color and/or the transparency of a legend shadow:
Users can define a color using the new color specification, (matplotlib_color, alpha).
Note that an explicit alpha keyword argument will override an alpha value from
(matplotlib_color, alpha).
The pie chart shadow can be controlled
The shadow argument to pie can now be a dict, allowing more control
of the Shadow-patch used.
PolyQuadMesh is a new class for drawing quadrilateral meshes
pcolor previously returned a flattened PolyCollection with only
the valid polygons (unmasked) contained within it. Now, we return a PolyQuadMesh,
which is a mixin incorporating the usefulness of 2D array and mesh coordinates
handling, but still inheriting the draw methods of PolyCollection, which enables
more control over the rendering properties than a normal QuadMesh that is
returned from pcolormesh. The new class subclasses PolyCollection and thus
should still behave the same as before. This new class keeps track of the mask for
the user and updates the Polygons that are sent to the renderer appropriately.
The Shadow patch now has a shade argument to control the shadow darkness.
If 1, the shadow is black, if 0, the shadow has the same color as the patch that
is shadowed. The default value, which earlier was fixed, is 0.7.
SpinesProxy now supports calling the set() method
One can now call e.g. ax.spines[:].set(visible=False).
Allow setting the tick label fonts with a keyword argument
Axes.tick_params now accepts a labelfontfamily keyword that changes the tick
label font separately from the rest of the text objects:
rcParams['legend.loc'] now accepts float-tuple inputs
The rcParams["legend.loc"] (default: 'best') rcParams now accepts float-tuple inputs, same as the loc keyword argument to Legend.
This allows users to set the location of the legend in a more flexible and consistent way.
Supports using the \boldsymbol{} command in mathtext:
To change symbols to bold enclose the text in a font command as
shown:
r'$\boldsymbol{a+2+\alpha}$'
a+2+α
mathtext has more sizable delimiters
The \lgroup and \rgroup sizable delimiters have been added.
The following delimiter names have been supported earlier, but can now be sized with
\left and \right:
\lbrace, \rbrace, \leftbrace, and \rightbrace
\lbrack and
mathtext documentation improvements
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 now supports \substack
\substack can be used to create multi-line subscripts or superscripts within an equation.
To use it to enclose the math in a substack command as shown:
The \middle delimiter has been added, and can now be used with the
\left and \right delimiters:
To use the middle command enclose it in between the \left and
\right delimiter command as shown:
r'$\left( \frac{a}{b} \middle| q \right)$'
mathtext operators
There has been a number of operators added and corrected when a Unicode font is used.
In addition, correct spacing has been added to a number of the previous operators.
Especially, the characters used for \gnapprox, \lnapprox, \leftangle, and
\rightangle have been corrected.
mathtext spacing corrections
As consequence of the updated documentation, the spacing on a number of relational and
operator symbols were classified like that and therefore will be spaced properly.
mathtext now supports \text
\text can be used to obtain upright text within an equation and to get a plain dash
(-).
importmatplotlib.pyplotaspltplt.text(0.1,0.5,r"$a = \sin(\phi) \text{ such that } \phi = \frac{x}{y}$")plt.text
Bold-italic mathtext command \mathbfit
Supports use of bold-italic font style in mathtext using the \mathbfit{} command:
To change font to bold and italic enclose the text in a font command as
shown:
r'$\mathbfit{\eta \leq C(\delta(\eta))}$
\mathbfitη≤C(δ(η))
3D plotting improvements
Specify ticks and axis label positions for 3D plots
You can now specify the positions of ticks and axis labels for 3D plots.
The x, y, z coordinates displayed in 3D plots were previously showing
nonsensical values. This has been fixed to report the coordinate on the view
pane directly beneath the mouse cursor. This is likely to be most useful when
viewing 3D plots along a primary axis direction when using an orthographic
projection, or when a 2D plot has been projected onto one of the 3D axis panes.
Note that there is still no way to directly display the coordinates of plotted
data points.
3D plots can share view angles
3D plots can now share the same view angles, so that when you rotate one plot
the other plots also rotate. This can be done with the shareview keyword
argument when adding an axes, or by using the ax1.shareview(ax2) method of
existing 3D axes.
Other improvements
macosx: New figures can be opened in either windows or tabs
There is a new rcParams["macosx.window_mode"] (default: 'system') rcParam to control how
new figures are opened with the macosx backend. The default is
system which uses the system settings, or one can specify either
tab or window to explicitly choose the mode used to open new figures.
matplotlib.mpl_toolkits is now an implicit namespace package
Following the deprecation of pkg_resources.declare_namespace in setuptools 67.3.0,
matplotlib.mpl_toolkits is now implemented as an implicit namespace, following
PEP 420.
Plot Directive now can make responsive images with "srcset"
The plot sphinx directive (matplotlib.sphinxext.plot_directive, invoked in
rst as ..plot::) can be configured to automatically make higher res
figures and add these to the built html docs. In conf.py: