On this page
matplotlib.axes
Table of Contents
- Inheritance
- The Axes class
- Subplots
- Clearing
- Appearance
- Property cycle
- Units
- Adding artists
- Twinning and sharing
- Axes position
- Async/event based
- Interactive
- Children
- Drawing
- Projection
- Other
Inheritance
The Axes class
- classmatplotlib.axes.Axes(fig, rect, *, facecolor=None, frameon=True, sharex=None, sharey=None, label='', xscale=None, yscale=None, box_aspect=None, **kwargs)[source]
-
Bases:
matplotlib.axes._base._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. - rect[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
scalar or None
(float, float) or {'C', 'SW', 'S', 'SE', 'E', 'NE', ...}
bool
{'auto', 'equal'} or float
bool
bool
bool
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
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
{"linear", "log", "symlog", "logit", ...} or
ScaleBase
unknown
unknown
unknown
str
(bottom: float, top: float)
float greater than -0.5
{"linear", "log", "symlog", "logit", ...} or
ScaleBase
unknown
unknown
float
- fig
- Returns
Subplots
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. |
|
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 axis. |
|
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. |
|
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 a 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
Return the XAxis instance. |
|
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 x-axis scale. |
|
Return the xaxis' scale (as a str). |
|
Set the y-axis 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 x-axis is autoscaled on the next draw or call to |
|
Return whether the x-axis is autoscaled. |
|
Set whether the y-axis is autoscaled on the next draw or call to |
|
Return whether the y-axis 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 a reference to the shared axes Grouper object for x axes. |
|
Return a reference to the shared axes Grouper object for y axes. |
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. |
|
If this property is set to True, the artist will be 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. |
|
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. |
© 2012–2021 Matplotlib Development Team. All rights reserved.
Licensed under the Matplotlib License Agreement.
https://matplotlib.org/3.5.1/api/axes_api.html