matplotlib.offsetbox
#
Container classes for Artist
s.
OffsetBox
The base of all container artists defined in this module.
AnchoredOffsetbox
, AnchoredText
Anchor and align an arbitrary Artist
or a text relative to the parent axes or a specific anchor point.
DrawingArea
A container with fixed width and height. Children have a fixed position inside the container and may be clipped.
HPacker
, VPacker
Containers for layouting their children vertically or horizontally.
PaddedBox
A container to add a padding around an Artist
.
TextArea
Contains a single Text
instance.
Bases: OffsetBox
An OffsetBox placed according to location loc.
AnchoredOffsetbox has a single child. When multiple children are needed, use an extra OffsetBox to enclose them. By default, the offset box is anchored against its parent Axes. You may explicitly specify the bbox_to_anchor.
The box location. 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 parameter loc of Legend
for details.
Padding around the child as fraction of the fontsize.
Padding between the offsetbox frame and the bbox_to_anchor.
OffsetBox
The box that will be anchored.
FontProperties
This is only used as a reference for paddings. If not given, rcParams["legend.fontsize"]
(default: 'medium'
) is used.
Whether to draw a frame around the box.
BboxBase
, 2-tuple, or 4-tuple of floats
Box that is used to position the legend in conjunction with loc.
matplotlib.transforms.Transform
The transform for the bounding box (bbox_to_anchor).
All other parameters are passed on to OffsetBox
.
Notes
See Legend
for a detailed description of the anchoring mechanism.
Update the location of children if necessary and draw them to the given renderer.
Return the bbox of the offsetbox, ignoring parent offsets.
Return the bbox that the box is anchored to.
Return the child.
Return the list of children.
Return the offset as a tuple (x, y).
The extent parameters have to be provided to handle the case where the offset is dynamically determined by a callable (see set_offset
).
Bbox
RendererBase
subclass
Set multiple properties at once.
Supported properties are
Set the bbox that the box is anchored to.
bbox can be a Bbox instance, a list of [left, bottom, width, height], or a list of [left, bottom] where the width and height will be assumed to be zero. The bbox will be transformed to display coordinate by the given transform.
Set the child to be anchored.
Bases: AnchoredOffsetbox
AnchoredOffsetbox with Text.
Text.
Location code. See AnchoredOffsetbox
.
Padding around the text as fraction of the fontsize.
Spacing between the offsetbox frame and the bbox_to_anchor.
Dictionary of keyword parameters to be passed to the Text
instance contained inside AnchoredText.
All other parameters are passed to AnchoredOffsetbox
.
Set multiple properties at once.
Supported properties are
Bases: Artist
, _AnnotationBase
Container for an OffsetBox
referring to a specific position xy.
Optionally an arrow pointing from the offsetbox to xy can be drawn.
This is like Annotation
, but with OffsetBox
instead of Text
.
OffsetBox
The point (x, y) to annotate. The coordinate system is determined by xycoords.
The position (x, y) to place the text at. The coordinate system is determined by boxcoords.
Artist
or Transform
or callable, default: 'data'
The coordinate system that xy is given in. See the parameter xycoords in Annotation
for a detailed description.
Artist
or Transform
or callable, default: value of xycoords
The coordinate system that xybox is given in. See the parameter textcoords in Annotation
for a detailed description.
By default, the text is surrounded by a white FancyBboxPatch
(accessible as the patch
attribute of the AnnotationBbox
). If frameon is set to False, this patch is made invisible.
Whether to clip (i.e. not draw) the annotation when the annotation point xy is outside the Axes area.
If True, the annotation will be clipped when xy is outside the Axes.
If False, the annotation will always be drawn.
If None, the annotation will be clipped when xy is outside the Axes and xycoords is 'data'.
Padding around the offsetbox.
A tuple of two floats for a vertical and horizontal alignment of the offset box w.r.t. the boxcoords. The lower-left corner is (0, 0) and upper-right corner is (1, 1).
A dictionary of properties to set for the annotation bounding box, for example boxstyle and alpha. See FancyBboxPatch
for details.
Arrow properties, see Annotation
for description.
Translated to points and passed as mutation_scale into FancyBboxPatch
to scale attributes of the box style (e.g. pad or rounding_size). The name is chosen in analogy to Text
where fontsize defines the mutation scale as well. If not given, rcParams["legend.fontsize"]
(default: 'medium'
) is used. See Text.set_fontsize
for valid values.
Other AnnotationBbox
properties. See AnnotationBbox.set
for a list.
Test whether the artist contains the mouse event.
MouseEvent
Whether any values are within the radius.
An artist-specific dictionary of details of the event context, such as which points are contained in the pick radius. See the individual Artist subclasses for details.
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).
RendererBase
subclass.
Notes
This method is overridden in the Artist subclasses.
Return the fontsize in points.
Get the artist's bounding box in display space, taking clipping into account.
RendererBase
, optional
Renderer used to draw the figure (i.e. fig.canvas.get_renderer()
).
Bbox
or None
The enclosing bounding box (in figure pixel coordinates), or None if clipping results in no intersection.
Get the artist's bounding box in display space, ignoring clipping.
The bounding box's width and height are non-negative.
Subclasses should override for inclusion in the bounding box "tight" calculation. Default is to return an empty bounding box at 0, 0.
Warning
The extent can change due to any changes in the transform stack, such as changing the Axes limits, the figure size, the canvas used (as is done when saving a figure), or the DPI.
Relying on a once-retrieved window extent can lead to unexpected behavior in various cases such as interactive figures being resized or moved to a screen with different dpi, or figures that look fine on screen render incorrectly when saved to file.
To get accurate results you may need to manually call savefig
or draw_without_rendering
to have Matplotlib compute the rendered size.
RendererBase
, optional
Renderer used to draw the figure (i.e. fig.canvas.get_renderer()
).
Set multiple properties at once.
Supported properties are
Set the Figure
or SubFigure
instance the artist belongs to.
Figure
or SubFigure
Set the fontsize in points.
If s is not given, reset to rcParams["legend.fontsize"]
(default: 'medium'
).
Update pixel positions for the annotated point, the text, and the arrow.
Bases: OffsetBox
An OffsetBox with an auxiliary transform.
All child artists are first transformed with aux_transform, then translated with an offset (the same for all children) so the bounding box of the children matches the drawn box. (In other words, adding an arbitrary translation to aux_transform has no effect as it will be cancelled out by the later offsetting.)
AuxTransformBox
is similar to DrawingArea
, except that the extent of the box is not predetermined but calculated from the window extent of its children, and the extent of the children will be calculated in the transformed coordinate.
Add an Artist
to the container box.
Update the location of children if necessary and draw them to the given renderer.
Return the bbox of the offsetbox, ignoring parent offsets.
Return offset of the container.
Return the Transform
applied to the children.
Set multiple properties at once.
Supported properties are
Set the offset of the container.
The (x, y) coordinates of the offset in display units.
set_transform is ignored.
Bases: DraggableBase
Bases: object
Helper base class for a draggable artist (legend, offsetbox).
Derived classes must override the following methods:
def save_offset(self): ''' Called when the object is picked for dragging; should save the reference position of the artist. ''' def update_offset(self, dx, dy): ''' Called during the dragging; (*dx*, *dy*) is the pixel offset from the point where the mouse drag started. '''
Optionally, you may override the following method:
def finalize_offset(self): '''Called when the mouse is released.'''
In the current implementation of DraggableLegend
and DraggableAnnotation
, update_offset
places the artists in display coordinates, and finalize_offset
recalculates their position in axes coordinate and set a relevant attribute.
Disconnect the callbacks.
Bases: DraggableBase
Bases: OffsetBox
The DrawingArea can contain any Artist as a child. The DrawingArea has a fixed width and height. The position of children relative to the parent is fixed. The children can be clipped at the boundaries of the parent.
Width and height of the container box.
Descent of the box in x- and y-direction.
Whether to clip the children to the box.
Add an Artist
to the container box.
If the children of this DrawingArea should be clipped by DrawingArea bounding box.
Update the location of children if necessary and draw them to the given renderer.
Return the bbox of the offsetbox, ignoring parent offsets.
Return offset of the container.
Return the Transform
applied to the children.
Set multiple properties at once.
Supported properties are
Set the offset of the container.
The (x, y) coordinates of the offset in display units.
set_transform is ignored.
Bases: PackerBase
HPacker packs its children horizontally, automatically adjusting their relative positions at draw time.
+-------------------------------+ | Child 1 Child 2 Child 3 | +-------------------------------+
The boundary padding in points.
The spacing between items in points.
Width and height of the container box in pixels, calculated if None.
Alignment of boxes.
The packing mode.
'fixed' packs the given Artist
s tight with sep spacing.
'expand' uses the maximal available space to distribute the artists with equal spacing in between.
'equal': Each artist an equal fraction of the available space and is left-aligned (or top-aligned) therein.
Artist
The artists to pack.
Notes
pad and sep are in points and will be scaled with the renderer dpi, while width and height are in pixels.
Set multiple properties at once.
Supported properties are
Bases: Artist
A simple container artist.
The child artists are meant to be drawn at a relative position to its parent.
Being an artist itself, all keyword arguments are passed on to Artist
.
The Axes
instance the artist resides in, or None.
Delegate the mouse event contains-check to the children.
As a container, the OffsetBox
does not respond itself to mouseevents.
MouseEvent
Whether any values are within the radius.
An artist-specific dictionary of details of the event context, such as which points are contained in the pick radius. See the individual Artist subclasses for details.
Update the location of children if necessary and draw them to the given renderer.
Return the bbox of the offsetbox, ignoring parent offsets.
Return a list of the child Artist
s.
Return the offset as a tuple (x, y).
The extent parameters have to be provided to handle the case where the offset is dynamically determined by a callable (see set_offset
).
Bbox
RendererBase
subclass
Return a list of the visible child Artist
s.
Get the artist's bounding box in display space, ignoring clipping.
The bounding box's width and height are non-negative.
Subclasses should override for inclusion in the bounding box "tight" calculation. Default is to return an empty bounding box at 0, 0.
Warning
The extent can change due to any changes in the transform stack, such as changing the Axes limits, the figure size, the canvas used (as is done when saving a figure), or the DPI.
Relying on a once-retrieved window extent can lead to unexpected behavior in various cases such as interactive figures being resized or moved to a screen with different dpi, or figures that look fine on screen render incorrectly when saved to file.
To get accurate results you may need to manually call savefig
or draw_without_rendering
to have Matplotlib compute the rendered size.
RendererBase
, optional
Renderer used to draw the figure (i.e. fig.canvas.get_renderer()
).
Set multiple properties at once.
Supported properties are
Set the Figure
for the OffsetBox
and all its children.
Figure
Set the height of the box.
Set the offset.
The (x, y) coordinates of the offset in display units. These can either be given explicitly as a tuple (x, y), or by providing a function that converts the extent into the offset. This function must have the signature:
def offset(width, height, xdescent, ydescent, renderer) -> (float, float)
Set the width of the box.
Bases: OffsetBox
Update the location of children if necessary and draw them to the given renderer.
Return the bbox of the offsetbox, ignoring parent offsets.
Return a list of the child Artist
s.
Return offset of the container.
Set multiple properties at once.
Supported properties are
Bases: OffsetBox
The boundary padding in points.
The spacing between items in points.
Width and height of the container box in pixels, calculated if None.
Alignment of boxes.
The packing mode.
'fixed' packs the given Artist
s tight with sep spacing.
'expand' uses the maximal available space to distribute the artists with equal spacing in between.
'equal': Each artist an equal fraction of the available space and is left-aligned (or top-aligned) therein.
Artist
The artists to pack.
Notes
pad and sep are in points and will be scaled with the renderer dpi, while width and height are in pixels.
Set multiple properties at once.
Supported properties are
Bases: OffsetBox
A container to add a padding around an Artist
.
The PaddedBox
contains a FancyBboxPatch
that is used to visualize it when rendering.
+----------------------------+ | | | | | | | <--pad--> Artist | | ^ | | pad | | v | +----------------------------+
The padding in points.
FancyBboxPatch
When draw_frame is True, this FancyBboxPatch
is made visible and creates a border around the box.
Artist
The contained Artist
.
The padding in points. This will be scaled with the renderer dpi. In contrast, width and height are in pixels and thus not scaled.
Whether to draw the contained FancyBboxPatch
.
Additional parameters passed to the contained FancyBboxPatch
.
Update the location of children if necessary and draw them to the given renderer.
Set multiple properties at once.
Supported properties are
Bases: OffsetBox
The TextArea is a container artist for a single Text instance.
The text is placed at (0, 0) with baseline+left alignment, by default. The width and height of the TextArea instance is the width and height of its child text.
The text to be displayed.
Dictionary of keyword parameters to be passed to the Text
instance in the TextArea.
Whether the baseline for multiline text is adjusted so that it is (approximately) center-aligned with single-line text.
Update the location of children if necessary and draw them to the given renderer.
Return the bbox of the offsetbox, ignoring parent offsets.
Get multilinebaseline.
Return offset of the container.
Return the string representation of this area's text.
Set multiple properties at once.
Supported properties are
Set multilinebaseline.
If True, the baseline for multiline text is adjusted so that it is (approximately) center-aligned with single-line text. This is used e.g. by the legend implementation so that single-line labels are baseline-aligned, but multiline labels are "center"-aligned with them.
Set the offset of the container.
The (x, y) coordinates of the offset in display units.
Set the text of this area as a string.
set_transform is ignored.
Bases: PackerBase
VPacker packs its children vertically, automatically adjusting their relative positions at draw time.
+---------+ | Child 1 | | Child 2 | | Child 3 | +---------+
The boundary padding in points.
The spacing between items in points.
Width and height of the container box in pixels, calculated if None.
Alignment of boxes.
The packing mode.
'fixed' packs the given Artist
s tight with sep spacing.
'expand' uses the maximal available space to distribute the artists with equal spacing in between.
'equal': Each artist an equal fraction of the available space and is left-aligned (or top-aligned) therein.
Artist
The artists to pack.
Notes
pad and sep are in points and will be scaled with the renderer dpi, while width and height are in pixels.
Set multiple properties at once.
Supported properties are
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4