matplotlib.projections
#
Non-separable transforms that map from data space to screen space.
Projections are defined asAxes
subclasses. They include thefollowing elements:
A transformation from data coordinates into display coordinates.
An inverse of that transformation. This is used, for example, to convertmouse positions from screen space back into data space.
Transformations for the gridlines, ticks and ticklabels. Custom projectionswill often need to place these elements in special locations, and Matplotlibhas a facility to help with doing so.
Setting up default values (overriding
cla
), since the defaultsfor a rectilinear Axes may not be appropriate.Defining the shape of the Axes, for example, an elliptical Axes, that will beused to draw the background of the plot and for clipping any data elements.
Defining custom locators and formatters for the projection. For example, ina geographic projection, it may be more convenient to display the grid indegrees, even if the data is in radians.
Set up interactive panning and zooming. This is left as an "advanced"feature left to the reader, but there is an example of this for polar plotsin
matplotlib.projections.polar
.Any additional methods for additional convenience or features.
Once the projection Axes is defined, it can be used in one of two ways:
By defining the class attribute
name
, the projection Axes can beregistered withmatplotlib.projections.register_projection
and subsequentlysimply invoked by name:fig.add_subplot(projection="my_proj_name")
For more complex, parameterisable projections, a generic "projection" objectmay be defined which includes the method
_as_mpl_axes
._as_mpl_axes
should take no arguments and return the projection's Axes subclass and adictionary of additional arguments to pass to the subclass'__init__
method. Subsequently a parameterised projection can be initialised with:fig.add_subplot(projection=MyProjection(param1=param1_value))
where MyProjection is an object which implements a
_as_mpl_axes
method.
A full-fledged and heavily annotated example is inCustom projection. The polar plot functionality inmatplotlib.projections.polar
may also be of interest.
- classmatplotlib.projections.ProjectionRegistry[source]#
Bases:
object
A mapping of registered projection names to projection classes.
- matplotlib.projections.get_projection_class(projection=None)[source]#
Get a projection class from its name.
Ifprojection is None, a standard rectilinear projection is returned.
- matplotlib.projections.get_projection_names()[source]#
Return the names of all projections currently registered.
Built-in projections#
Matplotlib has built-in support for polar and some geographic projections.See the following pages for more information: