Using ProPlot
This page offers a condensed overview of ProPlot’s features. It is populated with links to the API reference and User Guide. For a more in-depth discussion, see Why ProPlot?
Background
ProPlot is an object-oriented matplotlib wrapper. The “wrapper” part means that ProPlot’s features are largely a superset of matplotlib. You can use your favorite plotting commands like plot
, scatter
, contour
, and pcolor
like you always have. The “object-oriented” part means that ProPlot’s features are implemented with subclasses of the Figure
and Axes
classes.
If you tend to use pyplot
and are not familiar with figure and axes classes, check out this guide. from the matplotlib documentation. Working with objects directly tends to be more clear and concise than pyplot
, makes things easier when working with multiple figures and axes, and is certainly more “pythonic”. Therefore, although some ProPlot features may still work, we do not officially support the pyplot
API.
Importing proplot
Importing ProPlot immediately adds several new colormaps, property cycles, color names, and fonts to matplotlib. If you are only interested in these features, you may want to simply import ProPlot at the top of your script and do nothing else! We recommend importing ProPlot as follows:
import proplot as plot
This differentiates ProPlot from the usual plt
abbreviation reserved for the pyplot
module.
Figure and axes classes
Creating plots with ProPlot always begins with a call to the subplots
command:
fig, axs = plot.subplots(...)
The subplots
command is modeled after matplotlib’s native matplotlib.pyplot.subplots
command and is packed with new features.
Instead of native matplotlib.figure.Figure
and matplotlib.axes.Axes
classes, subplots
returns an instance of the proplot.figure.Figure
subclass populated with instances of proplot.axes.Axes
subclasses. Also, all ProPlot axes belong to one of the following three child classes:
proplot.axes.CartesianAxes
: For plotting ordinary data with x and y coordinates.proplot.axes.GeoAxes
: For geographic plots with longitude and latitude coordinates.proplot.axes.PolarAxes
: For polar plots with radius and azimuth coordinates.
Most of ProPlot’s features are added via the figure and axes subclasses. They include several brand new methods and add to the functionality of several existing methods.
The new
format
method is used to fine-tune various axes settings. Think of this as a dedicatedupdate
method for axes artists. See formatting subplots for a broad overview, along with the individual sections on formatting Cartesian plots, polar plots, and geographic projections.The
proplot.axes.Axes.colorbar
andproplot.axes.Axes.legend
commands are used to add colorbars and legends inside of subplots and along the outside edge of subplots. Theproplot.figure.Figure.colorbar
andproplot.figure.Figure.legend
commands are used to draw colorbars and legends along the edge of an entire figure, centered between subplot boundaries. These commands considerably simplify the process of drawing colorbars and legends.ProPlot adds a huge variety of features for working with the
plot
,bar
,area
,contour
,pcolormesh
,heatmap
, andparametric
plotting methods by “wrapping” them. See the 1D plotting and 2D plotting sections for details.
Integration with other packages
ProPlot includes optional integration features with four external packages: the pandas
and xarray
packages, used for working with annotated tables and arrays, and the cartopy
and basemap
cartographic plotting packages.
When you pass a
pandas.Series
,pandas.DataFrame
, orxarray.DataArray
to any plotting command, the axis labels, tick labels, titles, colorbar labels, and legend labels are automatically applied from the metadata. This works just like the nativexarray.DataArray.plot
andpandas.DataFrame.plot
methods. A demonstration of this feature is given in the sections on 1D plotting and 2D plotting.The
GeoAxes
class uses thecartopy
orbasemap
packages to plot geophysical data, add geographic features, and format projections. This is a much simpler, smoother interface than the originalcartopy
andbasemap
interfaces. Figures can be filled withGeoAxes
by using theproj
keyword argument withsubplots
.
Since these features are optional, ProPlot can be used without installing any of these packages.
New functions and classes
Outside of the Figure
and Axes
subclasses, ProPlot includes several useful constructor functions and subclasses.
The
Colormap
andCycle
constructor functions can be used to slice, and merge existing colormaps and color cycles. It can also make new colormaps and color cycles from scratch.The
LinearSegmentedColormap
andListedColormap
subclasses replace the default matplotlib colormap classes and add several methods. The newPerceptuallyUniformColormap
class is used to make colormaps with perceptually uniform transitions.The
show_cmaps
,show_cycles
,show_colors
,show_fonts
,show_channels
, andshow_colorspaces
functions are used to visualize your color scheme and font options and inspect individual colormaps.The
Norm
constructor function generates colormap normalizers from shorthand names. The newLinearSegmentedNorm
normalizer scales colors evenly w.r.t. index for arbitrarily spaced monotonic levels, and the newDiscreteNorm
meta-normalizer is used to break up colormap colors into discrete levels.The
Locator
,Formatter
, andScale
constructor functions return corresponding class instances from flexible input types. These are used to interpret keyword arguments passed toformat
, and can be used to quickly and easily modify x and y axis settings.The
rc
object, an instance ofRcConfigurator
, is used for modifying individual settings, changing settings in bulk, and temporarily changing settings in context blocks. It also introduces several new setings and sets up the inline plotting backend withinline_backend_fmt
so that your inline figures look the same as your saved figures.