matplotlib.axes
#
Inheritance#
The Axes class#
- class matplotlib.axes.Axes(fig, rect, *, facecolor=None, frameon=True, sharex=None, sharey=None, label='', xscale=None, yscale=None, box_aspect=None, **kwargs)[source]#
Bases:
_AxesBase
The
Axes
contains most of the figure elements:Axis
,Tick
,Line2D
,Text
,Polygon
, etc., and sets the coordinate system.The
Axes
instance supports callbacks through a callbacks attribute which is aCallbackRegistry
instance. The events you can connect to are 'xlim_changed' and 'ylim_changed' and the callback will be called with func(ax) where ax is theAxes
instance.- Attributes:
Build an Axes in a figure.
- Parameters:
- fig
Figure
The Axes is built in the
Figure
fig.- recttuple (left, bottom, width, height).
The Axes is built in the rectangle rect. rect is in
Figure
coordinates.- sharex, sharey
Axes
, optional The x or y
axis
is shared with the x or y axis in the inputAxes
.- frameonbool, default: True
Whether the Axes frame is visible.
- box_aspectfloat, optional
Set a fixed aspect for the Axes box, i.e. the ratio of height to width. See
set_box_aspect
for details.- **kwargs
Other optional keyword arguments:
Property
Description
{'box', 'datalim'}
a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image
scalar or None
(float, float) or {'C', 'SW', 'S', 'SE', 'E', 'NE', ...}
bool
{'auto', 'equal'} or float
bool
unknown
unknown
Callable[[Axes, Renderer], Bbox]
bool or 'line'
float or None
bool
Patch or (Path, Transform) or None
facecolor
or fccolor
bool
str
bool
object
bool
bool
unknown
None or bool or float or callable
[left, bottom, width, height] or
Bbox
unknown
float or None
bool
(scale: float, length: float, randomness: float)
bool or None
str
str
bool
unknown
str
(bottom: float, top: float)
float greater than -0.5
unknown
unknown
unknown
unknown
str
(bottom: float, top: float)
float greater than -0.5
unknown
unknown
unknown
float
- fig
- Returns:
Subplots#
Base class for subplots, which are |
|
Plotting#
Basic#
Plot y versus x as lines and/or markers. |
|
Plot y versus x as lines and/or markers with attached errorbars. |
|
A scatter plot of y vs. |
|
[Discouraged] Plot coercing the axis to treat floats as dates. |
|
Make a step plot. |
|
Make a plot with log scaling on both the x and y axis. |
|
Make a plot with log scaling on the x axis. |
|
Make a plot with log scaling on the y axis. |
|
Fill the area between two horizontal curves. |
|
Fill the area between two vertical curves. |
|
Make a bar plot. |
|
Make a horizontal bar plot. |
|
Label a bar plot. |
|
Create a stem plot. |
|
Plot identical parallel lines at the given positions. |
|
Plot a pie chart. |
|
Draw a stacked area plot. |
|
Plot a horizontal sequence of rectangles. |
|
Plot vertical lines at each x from ymin to ymax. |
|
Plot horizontal lines at each y from xmin to xmax. |
|
Plot filled polygons. |
Spans#
Add a horizontal line across the Axes. |
|
Add a horizontal span (rectangle) across the Axes. |
|
Add a vertical line across the Axes. |
|
Add a vertical span (rectangle) across the Axes. |
|
Add an infinitely long straight line. |
Spectral#
Plot the autocorrelation of x. |
|
Plot the angle spectrum. |
|
Plot the coherence between x and y. |
|
Plot the cross-spectral density. |
|
Plot the magnitude spectrum. |
|
Plot the phase spectrum. |
|
Plot the power spectral density. |
|
Plot a spectrogram. |
|
Plot the cross correlation between x and y. |
Statistics#
Draw a box and whisker plot. |
|
Make a violin plot. |
|
Drawing function for violin plots. |
|
Drawing function for box and whisker plots. |
Binned#
Make a 2D hexagonal binning plot of points x, y. |
|
Compute and plot a histogram. |
|
Make a 2D histogram plot. |
|
A stepwise constant function as a line with bounding edges or a filled plot. |
Contours#
Label a contour plot. |
|
Plot contour lines. |
|
Plot filled contours. |
2D arrays#
Display data as an image, i.e., on a 2D regular raster. |
|
Plot the values of a 2D matrix or array as color-coded image. |
|
Create a pseudocolor plot with a non-regular rectangular grid. |
|
Create a pseudocolor plot with a non-regular rectangular grid. |
|
Create a pseudocolor plot with a non-regular rectangular grid. |
|
Plot the sparsity pattern of a 2D array. |
Unstructured triangles#
Create a pseudocolor plot of an unstructured triangular grid. |
|
Draw an unstructured triangular grid as lines and/or markers. |
|
Draw contour lines on an unstructured triangular grid. |
|
Draw contour regions on an unstructured triangular grid. |
Text and annotations#
Annotate the point xy with text text. |
|
Add text to the Axes. |
|
Add a table to an |
|
Add an arrow to the Axes. |
|
Add a child inset Axes to this existing Axes. |
|
Add an inset indicator to the Axes. |
|
Add an inset indicator rectangle to the Axes based on the axis limits for an inset_ax and draw connectors between inset_ax and the rectangle. |
|
Add a second x-axis to this Axes. |
|
Add a second y-axis to this Axes. |
Vector fields#
Plot a 2D field of barbs. |
|
Plot a 2D field of arrows. |
|
Add a key to a quiver plot. |
|
Draw streamlines of a vector flow. |
Clearing#
Clear the Axes. |
|
Clear the Axes. |
Appearance#
Convenience method to get or set some axis properties. |
|
Turn the x- and y-axis off. |
|
Turn the x- and y-axis on. |
|
Set whether the Axes rectangle patch is drawn. |
|
Get whether the Axes rectangle patch is drawn. |
|
Set whether axis ticks and gridlines are above or below most artists. |
|
Get whether axis ticks and gridlines are above or below most artists. |
|
Configure the grid lines. |
|
Get the facecolor of the Axes. |
|
Set the facecolor of the Axes. |
Property cycle#
Set the property cycle of the Axes. |
Axis / limits#
[Discouraged] Return the XAxis instance. |
|
[Discouraged] Return the YAxis instance. |
Axis limits and direction#
Invert the x-axis. |
|
Return whether the xaxis is oriented in the "inverse" direction. |
|
Invert the y-axis. |
|
Return whether the yaxis is oriented in the "inverse" direction. |
|
Set the x-axis view limits. |
|
Return the x-axis view limits. |
|
Set the y-axis view limits. |
|
Return the y-axis view limits. |
|
Extend the |
|
Set the lower and upper numerical bounds of the x-axis. |
|
Return the lower and upper x-axis bounds, in increasing order. |
|
Set the lower and upper numerical bounds of the y-axis. |
|
Return the lower and upper y-axis bounds, in increasing order. |
Axis labels, title, and legend#
Set the label for the x-axis. |
|
Get the xlabel text string. |
|
Set the label for the y-axis. |
|
Get the ylabel text string. |
|
Set a title for the Axes. |
|
Get an Axes title. |
|
Place a legend on the Axes. |
|
Return the |
|
Return handles and labels for legend |
Axis scales#
Set the xaxis' scale. |
|
Return the xaxis' scale (as a str). |
|
Set the yaxis' scale. |
|
Return the yaxis' scale (as a str). |
Autoscaling and margins#
When autoscaling, whether to obey all |
|
Set or retrieve autoscaling margins. |
|
Set padding of X data limits prior to autoscaling. |
|
Set padding of Y data limits prior to autoscaling. |
|
Recompute the data limits based on current artists. |
|
Autoscale the axis view to the data (toggle). |
|
Autoscale the view limits using the data limits. |
|
Set whether autoscaling is applied to each axis on the next draw or call to |
|
Return True if each axis is autoscaled, False otherwise. |
|
Set whether the xaxis is autoscaled when drawing or by |
|
Return whether the xaxis is autoscaled. |
|
Set whether the yaxis is autoscaled when drawing or by |
|
Return whether the yaxis is autoscaled. |
Aspect ratio#
Adjust the Axes for a specified data aspect ratio. |
|
Set the aspect ratio of the axes scaling, i.e. y/x-scale. |
|
Return the aspect ratio of the axes scaling. |
|
Set the Axes box aspect, i.e. the ratio of height to width. |
|
Return the Axes box aspect, i.e. the ratio of height to width. |
|
Set how the Axes adjusts to achieve the required aspect ratio. |
|
Return whether the Axes will adjust its physical dimension ('box') or its data limits ('datalim') to achieve the desired aspect ratio. |
Ticks and tick labels#
Set the xaxis' tick locations and optionally labels. |
|
Return the xaxis' tick locations in data coordinates. |
|
Set the xaxis' labels with list of string labels. |
|
Get the xaxis' tick labels. |
|
Return the xaxis' major tick labels, as a list of |
|
Return the xaxis' minor tick labels, as a list of |
|
Return the xaxis' grid lines as a list of |
|
Return the xaxis' tick lines as a list of |
|
Set up axis ticks and labels to treat data along the xaxis as dates. |
|
Set the yaxis' tick locations and optionally labels. |
|
Return the yaxis' tick locations in data coordinates. |
|
Set the yaxis' labels with list of string labels. |
|
Get the yaxis' tick labels. |
|
Return the yaxis' major tick labels, as a list of |
|
Return the yaxis' minor tick labels, as a list of |
|
Return the yaxis' grid lines as a list of |
|
Return the yaxis' tick lines as a list of |
|
Set up axis ticks and labels to treat data along the yaxis as dates. |
|
Remove minor ticks from the Axes. |
|
Display minor ticks on the Axes. |
|
Configure the |
|
Change the appearance of ticks, tick labels, and gridlines. |
|
Control behavior of major tick locators. |
Units#
Convert x using the unit type of the xaxis. |
|
Convert y using the unit type of the yaxis. |
|
Return whether units are set on any axis. |
Adding artists#
Add an |
|
Add an |
|
Add a |
|
Add a |
|
Add an |
|
Add a |
|
Add a |
|
Add a |
Twinning and sharing#
Create a twin Axes sharing the xaxis. |
|
Create a twin Axes sharing the yaxis. |
|
Share the x-axis with other. |
|
Share the y-axis with other. |
|
Return an immutable view on the shared x-axes Grouper. |
|
Return an immutable view on the shared y-axes Grouper. |
Axes position#
Get the anchor location. |
|
Define the anchor location. |
|
Return the axes_locator. |
|
Set the Axes locator. |
|
Reset the active position to the original position. |
|
Return the position of the Axes within the figure as a |
|
Set the Axes position. |
Async/event based#
Whether the artist is 'stale' and needs to be re-drawn for the output to match the internal state of the artist. |
|
Call all of the registered callbacks. |
|
Add a callback function that will be called whenever one of the |
|
Remove a callback based on its observer id. |
Interactive#
Return whether this Axes supports any pan/zoom button functionality. |
|
Return whether this Axes supports the zoom box button functionality. |
|
Get whether the Axes responds to navigation commands. |
|
Set whether the Axes responds to navigation toolbar commands. |
|
Get the navigation toolbar button status: 'PAN', 'ZOOM', or None. |
|
Set the navigation toolbar button status. |
|
Called when a pan operation has started. |
|
Called when the mouse moves during a pan operation. |
|
Called when a pan operation completes (when the mouse button is up.) |
|
Return a format string formatting the x, y coordinates. |
|
Return a string representation of data. |
|
Return x formatted as an x-value. |
|
Return y formatted as an y-value. |
|
Return whether this artist is queried for custom context information when the mouse cursor moves over it. |
|
Return whether the given event (in display coords) is in the Axes. |
|
Test whether the artist contains the mouse event. |
|
Return whether point (pair of pixel coordinates) is inside the Axes patch. |
|
Return the cursor data for a given event. |
Children#
Return a list of |
|
Return a list of lines contained by the Axes. |
|
Find artist objects. |
Drawing#
Draw the Artist (and its children) using the given renderer. |
|
Efficiently redraw a single artist. |
|
Efficiently redraw Axes data, but not axis ticks, labels, etc. |
|
[Deprecated] |
|
Return the zorder value below which artists will be rasterized. |
|
Set the zorder threshold for rasterization for vector graphics output. |
|
Return the Axes bounding box in display space; args and kwargs are empty. |
|
Return the tight bounding box of the Axes, including axis and their decorators (xlabel, title, etc). |
Projection#
Methods used by Axis
that must be overridden for
non-rectilinear Axes.
Get the transformation used for drawing x-axis labels, ticks and gridlines. |
|
Get the transformation used for drawing y-axis labels, ticks and gridlines. |
|
Return the aspect ratio of the scaled data. |
|
|
|
|
|
|
|
|
Other#
Return a default list of artists that are used for the bounding box calculation. |
|
Return the clip path with the non-affine part of its transformation applied, and the remaining affine part of its transformation. |
|
Return whether any artists have been added to the Axes. |
|
Set multiple properties at once. |
- class matplotlib.axes.Axes.ArtistList(axes, prop_name, add_name, valid_types=None, invalid_types=None)#
A sublist of Axes children based on their type.
The type-specific children sublists will become immutable in Matplotlib 3.7. Then, these artist lists will likely be replaced by tuples. Use as if this is a tuple already.
This class exists only for the transition period to warn on the deprecated modification of artist lists.
- Parameters:
- axes.axes.Axes
The Axes from which this sublist will pull the children Artists.
- prop_namestr
The property name used to access this sublist from the Axes; used to generate deprecation warnings.
- add_namestr
The method name used to add Artists of this sublist's type to the Axes; used to generate deprecation warnings.
- valid_typeslist of type, optional
A list of types that determine which children will be returned by this sublist. If specified, then the Artists in the sublist must be instances of any of these types. If unspecified, then any type of Artist is valid (unless limited by invalid_types.)
- invalid_typestuple, optional
A list of types that determine which children will not be returned by this sublist. If specified, then Artists in the sublist will never be an instance of these types. Otherwise, no types will be excluded.
- insert(index, item)#
S.insert(index, value) -- insert value before index