Draft Forbes Group Website (Build by Nikola). The official site is hosted at:
License: GPL3
ubuntu2004
Matplotlib Subplot Placement
Here we describe how to local subplots in matplotlib.
Overview
We start with several figure components that we would like to arrange.
Here is a typical way of arranging the plots using subplots:
Now, what if we want to locate this composite figure? GridSpec is a good way to start. It allows you to generate a SubplotSpec which can be used to locate the components. We first need to update our previous figure-drawing components to draw-themselves in a SubplotSpec. We can reuse our previous functions (which use top-level plt.
functions) if we set the active axis.
Inset Axes
If you want to locate an axis precisely, you can use inset_axes
. You can control the location by specifying the transform:
bbox_transform=ax.transAxes
: Coordinates will be relative to the parent axis.bbox_transform=ax.transData
: Coordinates will be relative to the data points in the parent axis.bbox_transform=blended_transform_factory(ax.DataAxes, ax.transAxes)
: Data coordinates for and axis coordinates in .
Once this is done, locate the axis by specifying the bounding box and then the location relative to this:
bbox_t_anchor=(left, bottom, width, height)
: Bounding box in the specified coordinate system.loc
: Location such aslower left
orcenter
.
Here we place subaxes at particular locations along .