Creating figures

ProPlot works by subclassing the matplotlib Figure and Axes classes. You can generate grids of proplot Axes axes on a proplot Figure using the subplots command.

import proplot as plot
f, axs = plot.subplots(...)

Just like with the pyplot version, you can use subplots without arguments to generate a single-axes subplot or with ncols or nrows to set up simple grids of subplots.

Simple subplot grids

In the below example, we create a simple subplot grid with subplots, populate it with some lines, and modify the axes (see Axes object containers and The format command for details).

import proplot as plot
import numpy as np
state = np.random.RandomState(51423)
f, axs = plot.subplots(ncols=2)
axs[0].plot(2*(state.rand(100,5)-0.5).cumsum(axis=0), lw=2)
axs[0].format(xticks=20, xtickminor=False)
axs.format(suptitle='ProPlot API', title='Title', xlabel='x axis', ylabel='y axis')

Complex subplot grids

To draw complex subplot grids in matplotlib, you have to call add_subplot a bunch of times in sequence. In ProPlot, you pass a 2D array of integers to subplots. Just think of this array as a “picture” of your figure, where each unique integer corresponds to a unique axes and 0 corresponds to an empty space. See the below examples.

import proplot as plot
import numpy as np
state = np.random.RandomState(51423)
data = 2*(state.rand(100,5)-0.5).cumsum(axis=0)
# Complex grid
array = [[1,1,2,2],[0,3,3,0]]
f, axs = plot.subplots(array, axwidth=1.5)
axs.format(abc=True, abcloc='ul', suptitle='Complex subplot grid', xlabel='xlabel', ylabel='ylabel')
axs[2].plot(data, lw=2)
# Really complex grid
array = [[1,1,2],[1,1,6],[3,4,4],[3,5,5]]
f, axs = plot.subplots(array, width=5, span=False)
axs.format(suptitle='Really complex subplot grid', xlabel='xlabel', ylabel='ylabel', abc=True)
axs[0].plot(data, lw=2)
(<matplotlib.lines.Line2D at 0x7fbb7b65ac88>,
 <matplotlib.lines.Line2D at 0x7fbb7b610b00>,
 <matplotlib.lines.Line2D at 0x7fbb7b610c18>,
 <matplotlib.lines.Line2D at 0x7fbb7b626ba8>,
 <matplotlib.lines.Line2D at 0x7fbb7b6204e0>)

Subplot numbers and labels

ProPlot assigns unique numbers to subplots. The number order determines the order the subplots appear in the axes_grid and the order of “a-b-c” labels generated by format. If you did not provide a 2D array, the number order is row-major by default but can be made column-major by passing order='F' to subplots. The “a-b-c” label position and style can be changed with format.

import proplot as plot
f, axs = plot.subplots(nrows=8, ncols=8, axwidth=0.7, space=0)
axs.format(abc=True, abcloc='ur', xlabel='x axis', ylabel='y axis',
           xticks=[], yticks=[], suptitle='Flush subplot grid')

Axes object containers

Instead of an ndarray of axes, subplots returns a special axes_grid container. This container behaves like a python list, but lets you call any command on multiple axes at once. It supports both 2D indexing (e.g. axs[0,1]) and 1D indexing (e.g. axs[2]), and is row-major by default. Further, slicing an axes grid (e.g. axs[:,0]) returns another axes grid.

You can make your own axes_grid by passing a list of axes to the class. In the below example, the axes_grid returned by subplots is used to call The format command on several axes at once.

import proplot as plot
import numpy as np
state = np.random.RandomState(51423)
f, axs = plot.subplots(ncols=5, nrows=5, axwidth=0.8)
for ax in axs[1:,1:]:
    ax.plot(state.rand(10,4), color='gray7', cycle_kw={'linestyle':('-',':','--','-.')})
axs[0].format(color='black', linewidth=2)
axs.format(xlabel='xlabel', ylabel='ylabel', suptitle='Axes grid demo')