The Scatter plot with histograms example can be rewritten using make_axes_locatable:

axScatter = plt.subplot()
axScatter.scatter(x, y)
axScatter.set_aspect(1.)

# create new axes on the right and on the top of the current axes.
divider = make_axes_locatable(axScatter)
axHistx = divider.append_axes("top", size=1.2, pad=0.1, sharex=axScatter)
axHisty = divider.append_axes("right", size=1.2, pad=0.1, sharey=axScatter)

# the scatter plot:
# histograms
bins = np.arange(-lim, lim + binwidth, binwidth)
axHistx.hist(x, bins=bins)
axHisty.hist(y, bins=bins, orientation='horizontal')
The Scatter plot with histograms example can be rewritten using make_axes_locatable:

axScatter = plt.subplot()
axScatter.scatter(x, y)
axScatter.set_aspect(1.)

# create new axes on the right and on the top of the current axes.
divider = make_axes_locatable(axScatter)
axHistx = divider.append_axes("top", size=1.2, pad=0.1, sharex=axScatter)
axHisty = divider.append_axes("right", size=1.2, pad=0.1, sharey=axScatter)

# the scatter plot:
# histograms
bins = np.arange(-lim, lim + binwidth, binwidth)
axHistx.hist(x, bins=bins)
axHisty.hist(y, bins=bins, orientation='horizontal')
inset_locator.inset_axes creates an inset axes whose size is either fixed, or a fixed proportion of the parent axes:

inset_axes = inset_axes(parent_axes,
                        width="30%",  # width = 30% of parent_bbox
                        height=1.,  # height = 1 inch
                        loc='lower left')
These constraints are specified using classes from the axes_size module, namely:

from mpl_toolkits.axes_grid1.axes_size import Fixed, Scaled
vert = [Fixed(2), Scaled(2), Scaled(3)]
RGBAxes is a helper class to conveniently show RGB composite images. Like ImageGrid, the location of axes are adjusted so that the area occupied by them fits in a given rectangle. Also, the xaxis and yaxis of each axes are shared.

from mpl_toolkits.axes_grid1.axes_rgb import RGBAxes

fig = plt.figure()
ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8], pad=0.0)
r, g, b = get_rgb()  # r, g, b are 2D images.
ax.imshow_rgb(r, g, b)
inset_locator.zoomed_inset_axes creates an inset axes whose data scale is that of the parent axes multiplied by some factor, e.g.

inset_axes = zoomed_inset_axes(ax,
                               0.5,  # zoom = 0.5
                               loc='upper right')
Here, we demonstrate how to achieve the following layout: we want to position axes in a 3x4 grid (note that Divider makes row indices start from the bottom(!) of the grid):

+--------+--------+--------+--------+
| (2, 0) | (2, 1) | (2, 2) | (2, 3) |
+--------+--------+--------+--------+
| (1, 0) | (1, 1) | (1, 2) | (1, 3) |
+--------+--------+--------+--------+
| (0, 0) | (0, 1) | (0, 2) | (0, 3) |
+--------+--------+--------+--------+
twin without a transform argument assumes that the parasite axes has the same data transform as the host. This can be useful when you want the top(or right)-axis to have different tick-locations, tick-labels, or tick-formatter for bottom(or left)-axis.

ax2 = ax.twin() # now, ax2 is responsible for "top" axis and "right" axis
ax2.set_xticks([0., .5*np.pi, np.pi, 1.5*np.pi, 2*np.pi],
               labels=["0", r"$\frac{1}{2}\pi$",
                       r"$\pi$", r"$\frac{3}{2}\pi$", r"$2\pi$"])
The following bounds the inset axes to a box with 20% of the parent axes's height and 40% of the width. The size of the axes specified ([0, 0, 1, 1]) ensures that the axes completely fills the bounding box:

>>> parent_axes = plt.gca()
>>> ax_ins = plt.axes([0, 0, 1, 1])
>>> ip = InsetPosition(ax, [0.5, 0.1, 0.4, 0.2])
>>> ax_ins.set_axes_locator(ip)
Most commands in the axes_grid1 toolkit can take an axes_class keyword argument, and the commands create an axes of the given class. For example, to create a host subplot with axisartist.Axes,

import mpl_toolkits.axisartist as AA
from mpl_toolkits.axes_grid1 import host_subplot

host = host_subplot(111, axes_class=AA.Axes)
To display an ellipse in the upper left, with a width of 0.1 and height of 0.4 in data coordinates:

>>> box = AnchoredAuxTransformBox(ax.transData, loc='upper left')
>>> el = Ellipse((0, 0), width=0.1, height=0.4, angle=30)
>>> box.drawing_area.add_artist(el)
>>> ax.add_artist(box)

Recommend

Matplotlib Overview of mpl_toolkits.axes_grid1 axes_grid1 AxesDivider Class

Matplotlib Image tutorial Plotting numpy arrays as images Array Interpolation schemes

Matplotlib Image tutorial Plotting numpy arrays as images Examining a specific data range

Matplotlib Image tutorial Plotting numpy arrays as images Color scale reference

Matplotlib Image tutorial Plotting numpy arrays as images Applying pseudocolor schemes to image plots

Matplotlib Image tutorial Plotting numpy arrays as images

Matplotlib Image tutorial Importing image data into Numpy arrays

Matplotlib Image tutorial Startup commands

Matplotlib Pyplot tutorial Logarithmic and other nonlinear axes

Matplotlib Pyplot tutorial Working with text Annotating text

Matplotlib Pyplot tutorial Working with text Using mathematical expressions in text

Matplotlib Pyplot tutorial Working with text

Matplotlib Pyplot tutorial Working with multiple figures and axes

Matplotlib Pyplot tutorial Controlling line properties

Matplotlib Pyplot tutorial Plotting with categorical variables

Matplotlib Pyplot tutorial Plotting with keyword strings

Matplotlib Pyplot tutorial Intro to pyplot Formatting the style of your plot

Matplotlib Pyplot tutorial Intro to pyplot

Matplotlib Basic Usage Working with multiple Figures and Axes

Matplotlib Basic Usage Color mapped data

Matplotlib Basic Usage Axis scales and ticks Additional Axis objects

Matplotlib Basic Usage Axis scales and ticks Plotting dates and strings

Matplotlib Basic Usage Axis scales and ticks Tick locators and formatters

Matplotlib Basic Usage Axis scales and ticks Scales

Matplotlib Basic Usage Labelling plots Legends

Matplotlib Basic Usage Labelling plots Annotations

Matplotlib Basic Usage Labelling plots Using mathematical expressions in text

Matplotlib Basic Usage Labelling plots Axes labels and text

Matplotlib Basic Usage Styling Artists Linewidths, linestyles, and markersizes

Matplotlib Basic Usage Styling Artists Colors

Matplotlib Basic Usage Styling Artists

Matplotlib Basic Usage Coding styles Making a helper functions

Matplotlib Basic Usage Coding styles The object-oriented and the pyplot interfaces

Matplotlib Basic Usage Types of inputs to plotting functions

Matplotlib Basic Usage Parts of a Figure Figure

Matplotlib Basic Usage A simple example

Matplotlib Basic Usage

Matplotlib The Lifecycle of a Plot Saving our plot

Matplotlib The Lifecycle of a Plot Combining multiple visualizations

Matplotlib The Lifecycle of a Plot Customizing the plot

Matplotlib The Lifecycle of a Plot Controlling the style

Matplotlib The Lifecycle of a Plot Getting started

Matplotlib The Lifecycle of a Plot Our data

Customizing Matplotlib with style sheets and rcParams The matplotlibrc file The default matplotlibrc file

Customizing Matplotlib with style sheets and rcParams The matplotlibrc file

Customizing Matplotlib with style sheets and rcParams Using style sheets Temporary styling

Customizing Matplotlib with style sheets and rcParams Using style sheets Composing styles

Customizing Matplotlib with style sheets and rcParams Using style sheets Defining your own style

Customizing Matplotlib with style sheets and rcParams Using style sheets

Customizing Matplotlib with style sheets and rcParams Runtime rc settings Temporary rc settings

Customizing Matplotlib with style sheets and rcParams Runtime rc settings

Matplotlib origin and extent in imshow Explicit extent and axes limits

Matplotlib origin and extent in imshow Explicit extent

Matplotlib origin and extent in imshow Default extent

Matplotlib origin and extent in imshow

Matplotlib Autoscaling Working with collections

Matplotlib Autoscaling Controlling autoscale

Matplotlib Autoscaling Sticky edges

Matplotlib Autoscaling Margins