mpl_toolkits.axes_grid1.inset_locator.inset_axes#

mpl_toolkits.axes_grid1.inset_locator.inset_axes(parent_axes,width,height,loc='upperright',bbox_to_anchor=None,bbox_transform=None,axes_class=None,axes_kwargs=None,borderpad=0.5)[source]#

Create an inset axes with a given width and height.

Both sizes used can be specified either in inches or percentage.For example,:

inset_axes(parent_axes,width='40%',height='30%',loc='lower left')

creates in inset axes in the lower left corner ofparent_axes which spansover 30% in height and 40% in width of theparent_axes. Since the usageofinset_axes may become slightly tricky when exceeding such standardcases, it is recommended to readthe examples.

Parameters:
parent_axesmatplotlib.axes.Axes

Axes to place the inset axes.

width, heightfloat or str

Size of the inset axes to create. If a float is provided, it isthe size in inches, e.g.width=1.3. If a string is provided, it isthe size in relative units, e.g.width='40%'. By default, i.e. ifneitherbbox_to_anchor norbbox_transform are specified, thoseare relative to the parent_axes. Otherwise, they are to be understoodrelative to the bounding box provided viabbox_to_anchor.

locstr, default: 'upper right'

Location to place the inset axes. Valid locations are'upper left', 'upper center', 'upper right','center left', 'center', 'center right','lower left', 'lower center', 'lower right'.For backward compatibility, numeric values are accepted as well.See the parameterloc ofLegend for details.

bbox_to_anchortuple orBboxBase, optional

Bbox that the inset axes will be anchored to. If None,a tuple of (0, 0, 1, 1) is used ifbbox_transform is settoparent_axes.transAxes orparent_axes.figure.transFigure.Otherwise,parent_axes.bbox is used. If a tuple, can be either[left, bottom, width, height], or [left, bottom].If the kwargswidth and/orheight are specified in relative units,the 2-tuple [left, bottom] cannot be used. Note that,unlessbbox_transform is set, the units of the bounding boxare interpreted in the pixel coordinate. When usingbbox_to_anchorwith tuple, it almost always makes sense to also specifyabbox_transform. This might often be the axes transformparent_axes.transAxes.

bbox_transformTransform, optional

Transformation for the bbox that contains the inset axes.If None, atransforms.IdentityTransform is used. The valueofbbox_to_anchor (or the return value of its get_points method)is transformed by thebbox_transform and then interpretedas points in the pixel coordinate (which is dpi dependent).You may providebbox_to_anchor in some normalized coordinate,and give an appropriate transform (e.g.,parent_axes.transAxes).

axes_classAxes type, default:HostAxes

The type of the newly created inset axes.

axes_kwargsdict, optional

Keyword arguments to pass to the constructor of the inset axes.Valid arguments include:

Property

Description

adjustable

{'box', 'datalim'}

agg_filter

a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image

alpha

float or None

anchor

(float, float) or {'C', 'SW', 'S', 'SE', 'E', 'NE', ...}

animated

bool

aspect

{'auto', 'equal'} or float

autoscale_on

bool

autoscalex_on

unknown

autoscaley_on

unknown

axes_locator

Callable[[Axes, Renderer], Bbox]

axisbelow

bool or 'line'

box_aspect

float or None

clip_box

BboxBase or None

clip_on

bool

clip_path

Patch or (Path, Transform) or None

facecolor orfc

color

figure

Figure orSubFigure

forward_navigation_events

bool or "auto"

frame_on

bool

gid

str

in_layout

bool

label

object

mouseover

bool

navigate

bool

navigate_mode

unknown

path_effects

list ofAbstractPathEffect

picker

None or bool or float or callable

position

[left, bottom, width, height] orBbox

prop_cycle

Cycler

rasterization_zorder

float or None

rasterized

bool

sketch_params

(scale: float, length: float, randomness: float)

snap

bool or None

subplotspec

unknown

title

str

transform

Transform

url

str

visible

bool

xbound

(lower: float, upper: float)

xinverted

unknown

xlabel

str

xlim

(left: float, right: float)

xmargin

float greater than -0.5

xscale

unknown

xticklabels

unknown

xticks

unknown

ybound

(lower: float, upper: float)

yinverted

unknown

ylabel

str

ylim

(bottom: float, top: float)

ymargin

float greater than -0.5

yscale

unknown

yticklabels

unknown

yticks

unknown

zorder

float

borderpadfloat or (float, float), default: 0.5

Padding between inset axes and the bbox_to_anchor.If a float, the same padding is used for both x and y.If a tuple of two floats, it specifies the (x, y) padding.The units are axes font size, i.e. for a default font size of 10 pointsborderpad = 0.5 is equivalent to a padding of 5 points.

Added in version 3.11:Theborderpad parameter now accepts a tuple of (x, y) paddings.

Returns:
inset_axesaxes_class

Inset axes object created.

Notes

The meaning ofbbox_to_anchor andbbox_to_transform is interpreteddifferently from that of legend. The value of bbox_to_anchor(or the return value of its get_points method; the default isparent_axes.bbox) is transformed by the bbox_transform (the defaultis Identity transform) and then interpreted as points in the pixelcoordinate (which is dpi dependent).

Thus, following three calls are identical and creates an inset axeswith respect to theparent_axes:

axins=inset_axes(parent_axes,"30%","40%")axins=inset_axes(parent_axes,"30%","40%",bbox_to_anchor=parent_axes.bbox)axins=inset_axes(parent_axes,"30%","40%",bbox_to_anchor=(0,0,1,1),bbox_transform=parent_axes.transAxes)

Examples usingmpl_toolkits.axes_grid1.inset_locator.inset_axes#

Control the position and size of a colorbar with inset_locator.inset_axes

Control the position and size of a colorbar with inset_locator.inset_axes

Inset locator demo

Inset locator demo