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')
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_axes = inset_axes(parent_axes,
width="30%", # width = 30% of parent_bbox
height=1., # height = 1 inch
loc='lower left')
from mpl_toolkits.axes_grid1.axes_size import Fixed, Scaled
vert = [Fixed(2), Scaled(2), Scaled(3)]
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_axes = zoomed_inset_axes(ax,
0.5, # zoom = 0.5
loc='upper right')
+--------+--------+--------+--------+
| (2, 0) | (2, 1) | (2, 2) | (2, 3) |
+--------+--------+--------+--------+
| (1, 0) | (1, 1) | (1, 2) | (1, 3) |
+--------+--------+--------+--------+
| (0, 0) | (0, 1) | (0, 2) | (0, 3) |
+--------+--------+--------+--------+
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$"])
>>> 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)
import mpl_toolkits.axisartist as AA
from mpl_toolkits.axes_grid1 import host_subplot
host = host_subplot(111, axes_class=AA.Axes)
>>> 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
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 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
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