matplotlib.inset#

The inset module defines the InsetIndicator class, which draws the rectangle and connectors required for Axes.indicate_inset and Axes.indicate_inset_zoom.

class matplotlib.inset.InsetIndicator(bounds=None, inset_ax=None, zorder=None, **kwargs)[source]#

Bases: Artist

An artist to highlight an area of interest.

An inset indicator is a rectangle on the plot at the position indicated by bounds that optionally has lines that connect the rectangle to an inset Axes (Axes.inset_axes).

Added in version 3.10.

Parameters:
bounds[x0, y0, width, height], optional

Lower-left corner of rectangle to be marked, and its width and height. If not set, the bounds will be calculated from the data limits of inset_ax, which must be supplied.

inset_axAxes, optional

An optional inset Axes to draw connecting lines to. Two lines are drawn connecting the indicator box to the inset Axes on corners chosen so as to not overlap with the indicator box.

zorderfloat, default: 4.99

Drawing order of the rectangle and connector lines. The default, 4.99, is just below the default level of inset Axes.

**kwargs

Other keyword arguments are passed on to the Rectangle patch.

property connectors#
4-tuple of patches.ConnectionPatch or None

The four connector lines connecting to (lower_left, upper_left, lower_right upper_right) corners of inset_ax. Two lines are set with visibility to False, but the user can set the visibility to True if the automatic choice is not deemed correct.

draw(renderer)[source]#

Draw the Artist (and its children) using the given renderer.

This has no effect if the artist is not visible (Artist.get_visible returns False).

Parameters:
rendererRendererBase subclass.

Notes

This method is overridden in the Artist subclasses.

property rectangle#

Rectangle: the indicator frame.

set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, color=<UNSET>, edgecolor=<UNSET>, gid=<UNSET>, in_layout=<UNSET>, label=<UNSET>, linestyle=<UNSET>, linewidth=<UNSET>, mouseover=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, zorder=<UNSET>)[source]#

Set multiple properties at once.

Supported properties are

Property

Description

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

unknown

animated

bool

clip_box

BboxBase or None

clip_on

bool

clip_path

Patch or (Path, Transform) or None

color

color

edgecolor

color or None

figure

Figure or SubFigure

gid

str

in_layout

bool

label

object

linestyle

{'-', '--', '-.', ':', '', (offset, on-off-seq), ...}

linewidth

float or None

mouseover

bool

path_effects

list of AbstractPathEffect

picker

None or bool or float or callable

rasterized

bool

sketch_params

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

snap

bool or None

transform

Transform

url

str

visible

bool

zorder

float

set_alpha(alpha)[source]#

Set the alpha value used for blending - not supported on all backends.

Parameters:
alphafloat or None

alpha must be within the 0-1 range, inclusive.

set_color(c)[source]#

Set the edgecolor of the rectangle and the connectors, and the facecolor for the rectangle.

Parameters:
ccolor
set_edgecolor(color)[source]#

Set the edge color of the rectangle and the connectors.

Parameters:
colorcolor or None
set_linestyle(ls)[source]#

Set the linestyle of the rectangle and the connectors.

linestyle

description

'-' or 'solid'

solid line

'--' or 'dashed'

dashed line

'-.' or 'dashdot'

dash-dotted line

':' or 'dotted'

dotted line

'none', 'None', ' ', or ''

draw nothing

Alternatively a dash tuple of the following form can be provided:

(offset, onoffseq)

where onoffseq is an even length tuple of on and off ink in points.

Parameters:
ls{'-', '--', '-.', ':', '', (offset, on-off-seq), ...}

The line style.

set_linewidth(w)[source]#

Set the linewidth in points of the rectangle and the connectors.

Parameters:
wfloat or None
zorder = 4.99#