Plotting routines for CASA simulations

This module provides several routines to plot results from CASA simulations.

This module is supposed to be used together with read_casasim

Usage example

Reads in the Casa simulation with name L001ALMA_NN and plots the line cube and the integrated line emission. The output is in pdf (in the file L001.pdf)

import prodimopy.read_casasim as preadc
import prodimopy.plot_casasim as pplotc
from matplotlib.backends.backend_pdf import PdfPages

data = preadc.CasaSim("L001ALMA_NN")

with PdfPages("L001.pdf") as pdf:
  pc = pplotc.PlotCasasim(pdf)
  pc.plot_cube(data.cube,nrows=5,ncol=5)
  pc.plot_integrated(data.integrated)

Source documentation

class prodimopy.plot_casasim.PlotCasasim(pdf, labelspacing=1.0)[source]

Plot routines for casa simulation results.

This class can be used together with prodimoy.read_casasim

Parameters:
  • pdf (class:matplotlib.backends.backend_pdf.PdfPages) – this object is used to save the plots in a pdf file.

  • labelspacing (int) – the spacing for the x and y labels in images in arcseconds. i.e. 1 weans there will be an x(y) tick every 1 arcsec

add_beam(ax, image, color='white')[source]

adds a beam to a plot (axis).

Parameters:
  • ax (class:matplotlib.axes.Axes) – the axis for which the beam should be added

  • image (class:~prodimopy.read_casasim.CASAImage) – some kind of image (can also be a cube)

  • FIXME (is proberly not general yet) –

plot_cube(cube, nrow=3, ncol=3, cvel_idx=None, step=1, zlim=[None, None], rms=False, mJy=False, zlog=False, powerNormGamma=None, cb_format='%5.1f', cb_fraction=0.015, cb_pad=0.005, cb_extend='neither', cmap='inferno', vellabel_fontsize=5, clevels=None, ccolors=None, zoomto=None, idxchans=None, framecolor='white', fig=None, axes=None, beam_color='white', **kwargs)[source]

Plots a spectral line cube.

Parameters:

zoomto (float) – this parameters allows to zoom into the image. The unit is in arcsec. E.g. zoomto=1.0 will show the region around the the center ranging from -1.0 to 1.0 arcsec for the x and y axis. It is also possible to provide two values e.g. zoomto=[1.5,1] - region -1.5 to 1.0 arcsec for the x and -1.5 to 1.0 for the y axis.

chansarray_like(int,ndim=1)

list if indices for the channels (velocities) that should be shown. the correspoding images will be shown in the given order starting from top left - to bottom right.

plot_integrated_diff(imageObs, imageModel, imageDiff, zlim=[None, None], mJy=False, zoomto=None, **kwargs)[source]

Plots an image and its diff Model-Obs.

Parameters:

zoomto (float) – this parameters allows to zoom into the image. The unit is in arcsec. E.g. zoomto=1.0 will show the region around the the center ranging from -1.0 to 1.0 arcsec for the x and y axis.

plot_integrated(image, zlim=[None, None], mJy=False, cb_format='%5.1f', cb_show=True, cmap='inferno', clabel=None, zoomto=None, clevels=None, ccolors=None, cb_fraction=0.04, zlog=False, powerNormGamma=None, showBeam=True, cb_pad=0.02, cb_extend='neither', ax=None, **kwargs)[source]

Plots a zeroth moment image (integrated intensity) image.

Parameters:
  • zoomto (float) – this parameters allows to zoom into the image. The unit is in arcsec. E.g. zoomto=1.0 will show the region around the the center ranging from -1.0 to 1.0 arcsec for the x and y axis.

  • ax (Axes) – An matplotlic Axes object that is used to make the plot. if ‘None’ an new one will be created.

plot_mom1_diff(imageObs, imageModel, imageDiff, zlim=[None, None], zoomto=None, **kwargs)[source]

Plots the moment 1 observations , model and the difference map.

Parameters:

zoomto (float) – this parameters allows to zoom into the image. The unit is in arcsec. E.g. zoomto=1.0 will show the region around the the center ranging from -1.0 to 1.0 arcsec for the x and y axis.

plot_mom1(image, zlim=[None, None], zoomto=None, cb_extend='neither', **kwargs)[source]

Plots the momement 1 map.

Parameters:

zoomto (float) – this parameters allows to zoom into the image. The unit is in arcsec. E.g. zoomto=1.0 will show the region around the the center ranging from -1.0 to 1.0 arcsec for the x and y axis.

plot_pv(image, zlim=[None, None], ylim=[None, None], mJy=False, **kwargs)[source]

Plots a position-velocity diagram.

Todo

  • it is not possible to set the xlim (offset) coordinate in arcsec. Requires likely the conversion form pix to arcsec or vice versa

plot_specprof(specprof, models=None, xlim=[None, None], modelNames=None, **kwargs)[source]

Plots a spectral profile (histogram style).

plot_radprof(radprof, models=None, modelNames=None, pmGrayBox=0.25, **kwargs)[source]

Plots a radial profile.

specprof_xy_hist(specprof)[source]

Produce x,y coordinates to plot spectral profile in histogram style.

class prodimopy.plot_casasim.AnchoredRectangle(transform, width, height, loc, pad=0.1, borderpad=0.1, prop=None, frameon=False, color='white')[source]

Draw a rectangle the size in data coordinate of the give axes.

pad, borderpad in fraction of the legend font size (or prop) adapted from AnchoredEllipse

add_callback(func)

Add a callback function that will be called whenever one of the .Artist’s properties changes.

Parameters:

func (callable) –

The callback function. It must have the signature:

def func(artist: Artist) -> Any

where artist is the calling .Artist. Return values may exist but are ignored.

Returns:

The observer id associated with the callback. This id can be used for removing the callback with .remove_callback later.

Return type:

int

See also

remove_callback

property axes

The ~.axes.Axes instance the artist resides in, or None.

codes = {'center': 10, 'center left': 6, 'center right': 7, 'lower center': 8, 'lower left': 3, 'lower right': 4, 'right': 5, 'upper center': 9, 'upper left': 2, 'upper right': 1}
contains(mouseevent)

Delegate the mouse event contains-check to the children.

As a container, the .OffsetBox does not respond itself to mouseevents.

Parameters:

mouseevent (matplotlib.backend_bases.MouseEvent) –

Returns:

  • contains (bool) – Whether any values are within the radius.

  • details (dict) – 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.

See also

Artist.contains

convert_xunits(x)

Convert x using the unit type of the xaxis.

If the artist is not in contained in an Axes or if the xaxis does not have units, x itself is returned.

convert_yunits(y)

Convert y using the unit type of the yaxis.

If the artist is not in contained in an Axes or if the yaxis does not have units, y itself is returned.

draw(renderer)

Update the location of children if necessary and draw them to the given renderer.

findobj(match=None, include_self=True)

Find artist objects.

Recursively find all .Artist instances contained in the artist.

Parameters:
  • match

    A filter criterion for the matches. This can be

    • None: Return all objects contained in artist.

    • A function with signature def match(artist: Artist) -> bool. The result will only contain artists for which the function returns True.

    • A class instance: e.g., .Line2D. The result will only contain artists of this class or its subclasses (isinstance check).

  • include_self (bool) – Include self in the list to be checked for a match.

Return type:

list of .Artist

format_cursor_data(data)

Return a string representation of data.

Note

This method is intended to be overridden by artist subclasses. As an end-user of Matplotlib you will most likely not call this method yourself.

The default implementation converts ints and floats and arrays of ints and floats into a comma-separated string enclosed in square brackets, unless the artist has an associated colorbar, in which case scalar values are formatted using the colorbar’s formatter.

See also

get_cursor_data

get_agg_filter()

Return filter function to be used for agg filter.

get_alpha()

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

get_animated()

Return whether the artist is animated.

get_bbox_to_anchor()

Return the bbox that the box is anchored to.

get_child()

Return the child.

get_children()

Return the list of children.

get_clip_box()

Return the clipbox.

get_clip_on()

Return whether the artist uses clipping.

get_clip_path()

Return the clip path.

get_cursor_data(event)

Return the cursor data for a given event.

Note

This method is intended to be overridden by artist subclasses. As an end-user of Matplotlib you will most likely not call this method yourself.

Cursor data can be used by Artists to provide additional context information for a given event. The default implementation just returns None.

Subclasses can override the method and return arbitrary data. However, when doing so, they must ensure that .format_cursor_data can convert the data to a string representation.

The only current use case is displaying the z-value of an .AxesImage in the status bar of a plot window, while moving the mouse.

Parameters:

event (matplotlib.backend_bases.MouseEvent) –

get_extent(renderer)

Return the extent of the box as (width, height, x, y).

This is the extent of the child plus the padding.

get_extent_offsets(renderer)

Update offset of the children and return the extent of the box.

Parameters:

renderer (.RendererBase subclass) –

Returns:

  • width

  • height

  • xdescent

  • ydescent

  • list of (xoffset, yoffset) pairs

get_figure()

Return the .Figure instance the artist belongs to.

get_gid()

Return the group id.

get_in_layout()

Return boolean flag, True if artist is included in layout calculations.

E.g. /tutorials/intermediate/constrainedlayout_guide, .Figure.tight_layout(), and fig.savefig(fname, bbox_inches='tight').

get_label()

Return the label used for this artist in the legend.

get_offset(width, height, xdescent, ydescent, renderer)

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 ~.OffsetBox.set_offset).

Parameters:
  • width – Extent parameters.

  • height – Extent parameters.

  • xdescent – Extent parameters.

  • ydescent – Extent parameters.

  • renderer (.RendererBase subclass) –

get_path_effects()
get_picker()

Return the picking behavior of the artist.

The possible values are described in .set_picker.

See also

set_picker, pickable, pick

get_rasterized()

Return whether the artist is to be rasterized.

get_sketch_params()

Return the sketch parameters for the artist.

Returns:

A 3-tuple with the following elements:

  • scale: The amplitude of the wiggle perpendicular to the source line.

  • length: The length of the wiggle along the line.

  • randomness: The scale factor by which the length is shrunken or expanded.

Returns None if no sketch parameters were set.

Return type:

tuple or None

get_snap()

Return the snap setting.

See .set_snap for details.

get_tightbbox(renderer)

Like .Artist.get_window_extent, but includes any clipping.

Parameters:

renderer (.RendererBase subclass) – renderer that will be used to draw the figures (i.e. fig.canvas.get_renderer())

Returns:

The enclosing bounding box (in figure pixel coordinates).

Return type:

.Bbox

get_transform()

Return the .Transform instance used by this artist.

get_transformed_clip_path_and_affine()

Return the clip path with the non-affine part of its transformation applied, and the remaining affine part of its transformation.

get_url()

Return the url.

get_visible()

Return the visibility.

get_visible_children()

Return a list of the visible child .Artists.

get_window_extent(renderer)

Get the artist’s bounding box in display space.

The bounding box’ width and height are nonnegative.

Subclasses should override for inclusion in the bounding box “tight” calculation. Default is to return an empty bounding box at 0, 0.

Be careful when using this function, the results will not update if the artist window extent of the artist changes. The extent can change due to any changes in the transform stack, such as changing the axes limits, the figure size, or the canvas used (as is done when saving a figure). This can lead to unexpected behavior where interactive figures will look fine on the screen, but will save incorrectly.

get_zorder()

Return the artist’s zorder.

have_units()

Return whether units are set on any axis.

is_transform_set()

Return whether the Artist has an explicitly set transform.

This is True after .set_transform has been called.

property mouseover

If this property is set to True, the artist will be queried for custom context information when the mouse cursor moves over it.

See also get_cursor_data(), ToolCursorPosition and NavigationToolbar2.

pchanged()

Call all of the registered callbacks.

This function is triggered internally when a property is changed.

pick(mouseevent)

Process a pick event.

Each child artist will fire a pick event if mouseevent is over the artist and the artist has picker set.

pickable()

Return whether the artist is pickable.

properties()

Return a dictionary of all the properties of the artist.

remove()

Remove the artist from the figure if possible.

The effect will not be visible until the figure is redrawn, e.g., with .FigureCanvasBase.draw_idle. Call ~.axes.Axes.relim to update the axes limits if desired.

Note: ~.axes.Axes.relim will not see collections even if the collection was added to the axes with autolim = True.

Note: there is no support for removing the artist’s legend entry.

remove_callback(oid)

Remove a callback based on its observer id.

See also

add_callback

set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, bbox_to_anchor=<UNSET>, child=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, gid=<UNSET>, height=<UNSET>, in_layout=<UNSET>, label=<UNSET>, offset=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, width=<UNSET>, zorder=<UNSET>)

Set multiple properties at once.

Supported properties are

Properties:

agg_filter: a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array alpha: scalar or None animated: bool bbox_to_anchor: unknown child: unknown clip_box: .Bbox clip_on: bool clip_path: Patch or (Path, Transform) or None figure: ~matplotlib.figure.Figure gid: str height: float in_layout: bool label: object offset: (float, float) or callable path_effects: .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 width: float zorder: float

set_agg_filter(filter_func)

Set the agg filter.

Parameters:

filter_func (callable) –

A filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array.

set_alpha(alpha)

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

Parameters:

alpha (scalar or None) – alpha must be within the 0-1 range, inclusive.

set_animated(b)

Set whether the artist is intended to be used in an animation.

If True, the artist is excluded from regular drawing of the figure. You have to call .Figure.draw_artist / .Axes.draw_artist explicitly on the artist. This appoach is used to speed up animations using blitting.

See also matplotlib.animation and /tutorials/advanced/blitting.

Parameters:

b (bool) –

set_bbox_to_anchor(bbox, transform=None)

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_child(child)

Set the child to be anchored.

set_clip_box(clipbox)

Set the artist’s clip .Bbox.

Parameters:

clipbox (.Bbox) –

set_clip_on(b)

Set whether the artist uses clipping.

When False artists will be visible outside of the axes which can lead to unexpected results.

Parameters:

b (bool) –

set_clip_path(path, transform=None)

Set the artist’s clip path.

Parameters:
  • path (.Patch or .Path or .TransformedPath or None) – The clip path. If given a .Path, transform must be provided as well. If None, a previously set clip path is removed.

  • transform (~matplotlib.transforms.Transform, optional) – Only used if path is a .Path, in which case the given .Path is converted to a .TransformedPath using transform.

Notes

For efficiency, if path is a .Rectangle this method will set the clipping box to the corresponding rectangle and set the clipping path to None.

For technical reasons (support of ~.Artist.set), a tuple (path, transform) is also accepted as a single positional parameter.

set_figure(fig)

Set the .Figure for the .OffsetBox and all its children.

Parameters:

fig (~matplotlib.figure.Figure) –

set_gid(gid)

Set the (group) id for the artist.

Parameters:

gid (str) –

set_height(height)

Set the height of the box.

Parameters:

height (float) –

set_in_layout(in_layout)

Set if artist is to be included in layout calculations, E.g. /tutorials/intermediate/constrainedlayout_guide, .Figure.tight_layout(), and fig.savefig(fname, bbox_inches='tight').

Parameters:

in_layout (bool) –

set_label(s)

Set a label that will be displayed in the legend.

Parameters:

s (object) – s will be converted to a string by calling str.

set_offset(xy)

Set the offset.

Parameters:

xy ((float, float) or callable) –

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_path_effects(path_effects)

Set the path effects.

Parameters:

path_effects (.AbstractPathEffect) –

set_picker(picker)

Define the picking behavior of the artist.

Parameters:

picker (None or bool or float or callable) –

This can be one of the following:

  • None: Picking is disabled for this artist (default).

  • A boolean: If True then picking will be enabled and the artist will fire a pick event if the mouse event is over the artist.

  • A float: If picker is a number it is interpreted as an epsilon tolerance in points and the artist will fire off an event if its data is within epsilon of the mouse event. For some artists like lines and patch collections, the artist may provide additional data to the pick event that is generated, e.g., the indices of the data within epsilon of the pick event

  • A function: If picker is callable, it is a user supplied function which determines whether the artist is hit by the mouse event:

    hit, props = picker(artist, mouseevent)
    

    to determine the hit test. if the mouse event is over the artist, return hit=True and props is a dictionary of properties you want added to the PickEvent attributes.

set_rasterized(rasterized)

Force rasterized (bitmap) drawing for vector graphics output.

Rasterized drawing is not supported by all artists. If you try to enable this on an artist that does not support it, the command has no effect and a warning will be issued.

This setting is ignored for pixel-based output.

See also /gallery/misc/rasterization_demo.

Parameters:

rasterized (bool) –

set_sketch_params(scale=None, length=None, randomness=None)

Set the sketch parameters.

Parameters:
  • scale (float, optional) – The amplitude of the wiggle perpendicular to the source line, in pixels. If scale is None, or not provided, no sketch filter will be provided.

  • length (float, optional) – The length of the wiggle along the line, in pixels (default 128.0)

  • randomness (float, optional) –

    The scale factor by which the length is shrunken or expanded (default 16.0)

    The PGF backend uses this argument as an RNG seed and not as described above. Using the same seed yields the same random shape.

set_snap(snap)

Set the snapping behavior.

Snapping aligns positions with the pixel grid, which results in clearer images. For example, if a black line of 1px width was defined at a position in between two pixels, the resulting image would contain the interpolated value of that line in the pixel grid, which would be a grey value on both adjacent pixel positions. In contrast, snapping will move the line to the nearest integer pixel value, so that the resulting image will really contain a 1px wide black line.

Snapping is currently only supported by the Agg and MacOSX backends.

Parameters:

snap (bool or None) –

Possible values:

  • True: Snap vertices to the nearest pixel center.

  • False: Do not modify vertex positions.

  • None: (auto) If the path contains only rectilinear line segments, round to the nearest pixel center.

set_transform(t)

Set the artist transform.

Parameters:

t (.Transform) –

set_url(url)

Set the url for the artist.

Parameters:

url (str) –

set_visible(b)

Set the artist’s visibility.

Parameters:

b (bool) –

set_width(width)

Set the width of the box.

Parameters:

width (float) –

set_zorder(level)

Set the zorder for the artist. Artists with lower zorder values are drawn first.

Parameters:

level (float) –

property stale

Whether the artist is ‘stale’ and needs to be re-drawn for the output to match the internal state of the artist.

property sticky_edges

x and y sticky edge lists for autoscaling.

When performing autoscaling, if a data limit coincides with a value in the corresponding sticky_edges list, then no margin will be added–the view limit “sticks” to the edge. A typical use case is histograms, where one usually expects no margin on the bottom edge (0) of the histogram.

Moreover, margin expansion “bumps” against sticky edges and cannot cross them. For example, if the upper data limit is 1.0, the upper view limit computed by simple margin application is 1.2, but there is a sticky edge at 1.1, then the actual upper view limit will be 1.1.

This attribute cannot be assigned to; however, the x and y lists can be modified in place as needed.

Examples

>>> artist.sticky_edges.x[:] = (xmin, xmax)
>>> artist.sticky_edges.y[:] = (ymin, ymax)
update(props)

Update this artist’s properties from the dict props.

Parameters:

props (dict) –

update_frame(bbox, fontsize=None)
update_from(other)

Copy properties from other to self.

zorder = 5
class prodimopy.plot_casasim.AnchoredEllipse(transform, width, height, angle, loc, pad=0.1, borderpad=0.1, prop=None, frameon=False, color='white')[source]

Draw an ellipse the size in data coordinate of the give axes.

pad, borderpad in fraction of the legend font size (or prop) Copied from https://matplotlib.org/mpl_toolkits/axes_grid/api/anchored_artists_api.html Adapted it a bit (I think)

Check how to use original class properly.

add_callback(func)

Add a callback function that will be called whenever one of the .Artist’s properties changes.

Parameters:

func (callable) –

The callback function. It must have the signature:

def func(artist: Artist) -> Any

where artist is the calling .Artist. Return values may exist but are ignored.

Returns:

The observer id associated with the callback. This id can be used for removing the callback with .remove_callback later.

Return type:

int

See also

remove_callback

property axes

The ~.axes.Axes instance the artist resides in, or None.

codes = {'center': 10, 'center left': 6, 'center right': 7, 'lower center': 8, 'lower left': 3, 'lower right': 4, 'right': 5, 'upper center': 9, 'upper left': 2, 'upper right': 1}
contains(mouseevent)

Delegate the mouse event contains-check to the children.

As a container, the .OffsetBox does not respond itself to mouseevents.

Parameters:

mouseevent (matplotlib.backend_bases.MouseEvent) –

Returns:

  • contains (bool) – Whether any values are within the radius.

  • details (dict) – 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.

See also

Artist.contains

convert_xunits(x)

Convert x using the unit type of the xaxis.

If the artist is not in contained in an Axes or if the xaxis does not have units, x itself is returned.

convert_yunits(y)

Convert y using the unit type of the yaxis.

If the artist is not in contained in an Axes or if the yaxis does not have units, y itself is returned.

draw(renderer)

Update the location of children if necessary and draw them to the given renderer.

findobj(match=None, include_self=True)

Find artist objects.

Recursively find all .Artist instances contained in the artist.

Parameters:
  • match

    A filter criterion for the matches. This can be

    • None: Return all objects contained in artist.

    • A function with signature def match(artist: Artist) -> bool. The result will only contain artists for which the function returns True.

    • A class instance: e.g., .Line2D. The result will only contain artists of this class or its subclasses (isinstance check).

  • include_self (bool) – Include self in the list to be checked for a match.

Return type:

list of .Artist

format_cursor_data(data)

Return a string representation of data.

Note

This method is intended to be overridden by artist subclasses. As an end-user of Matplotlib you will most likely not call this method yourself.

The default implementation converts ints and floats and arrays of ints and floats into a comma-separated string enclosed in square brackets, unless the artist has an associated colorbar, in which case scalar values are formatted using the colorbar’s formatter.

See also

get_cursor_data

get_agg_filter()

Return filter function to be used for agg filter.

get_alpha()

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

get_animated()

Return whether the artist is animated.

get_bbox_to_anchor()

Return the bbox that the box is anchored to.

get_child()

Return the child.

get_children()

Return the list of children.

get_clip_box()

Return the clipbox.

get_clip_on()

Return whether the artist uses clipping.

get_clip_path()

Return the clip path.

get_cursor_data(event)

Return the cursor data for a given event.

Note

This method is intended to be overridden by artist subclasses. As an end-user of Matplotlib you will most likely not call this method yourself.

Cursor data can be used by Artists to provide additional context information for a given event. The default implementation just returns None.

Subclasses can override the method and return arbitrary data. However, when doing so, they must ensure that .format_cursor_data can convert the data to a string representation.

The only current use case is displaying the z-value of an .AxesImage in the status bar of a plot window, while moving the mouse.

Parameters:

event (matplotlib.backend_bases.MouseEvent) –

get_extent(renderer)

Return the extent of the box as (width, height, x, y).

This is the extent of the child plus the padding.

get_extent_offsets(renderer)

Update offset of the children and return the extent of the box.

Parameters:

renderer (.RendererBase subclass) –

Returns:

  • width

  • height

  • xdescent

  • ydescent

  • list of (xoffset, yoffset) pairs

get_figure()

Return the .Figure instance the artist belongs to.

get_gid()

Return the group id.

get_in_layout()

Return boolean flag, True if artist is included in layout calculations.

E.g. /tutorials/intermediate/constrainedlayout_guide, .Figure.tight_layout(), and fig.savefig(fname, bbox_inches='tight').

get_label()

Return the label used for this artist in the legend.

get_offset(width, height, xdescent, ydescent, renderer)

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 ~.OffsetBox.set_offset).

Parameters:
  • width – Extent parameters.

  • height – Extent parameters.

  • xdescent – Extent parameters.

  • ydescent – Extent parameters.

  • renderer (.RendererBase subclass) –

get_path_effects()
get_picker()

Return the picking behavior of the artist.

The possible values are described in .set_picker.

See also

set_picker, pickable, pick

get_rasterized()

Return whether the artist is to be rasterized.

get_sketch_params()

Return the sketch parameters for the artist.

Returns:

A 3-tuple with the following elements:

  • scale: The amplitude of the wiggle perpendicular to the source line.

  • length: The length of the wiggle along the line.

  • randomness: The scale factor by which the length is shrunken or expanded.

Returns None if no sketch parameters were set.

Return type:

tuple or None

get_snap()

Return the snap setting.

See .set_snap for details.

get_tightbbox(renderer)

Like .Artist.get_window_extent, but includes any clipping.

Parameters:

renderer (.RendererBase subclass) – renderer that will be used to draw the figures (i.e. fig.canvas.get_renderer())

Returns:

The enclosing bounding box (in figure pixel coordinates).

Return type:

.Bbox

get_transform()

Return the .Transform instance used by this artist.

get_transformed_clip_path_and_affine()

Return the clip path with the non-affine part of its transformation applied, and the remaining affine part of its transformation.

get_url()

Return the url.

get_visible()

Return the visibility.

get_visible_children()

Return a list of the visible child .Artists.

get_window_extent(renderer)

Get the artist’s bounding box in display space.

The bounding box’ width and height are nonnegative.

Subclasses should override for inclusion in the bounding box “tight” calculation. Default is to return an empty bounding box at 0, 0.

Be careful when using this function, the results will not update if the artist window extent of the artist changes. The extent can change due to any changes in the transform stack, such as changing the axes limits, the figure size, or the canvas used (as is done when saving a figure). This can lead to unexpected behavior where interactive figures will look fine on the screen, but will save incorrectly.

get_zorder()

Return the artist’s zorder.

have_units()

Return whether units are set on any axis.

is_transform_set()

Return whether the Artist has an explicitly set transform.

This is True after .set_transform has been called.

property mouseover

If this property is set to True, the artist will be queried for custom context information when the mouse cursor moves over it.

See also get_cursor_data(), ToolCursorPosition and NavigationToolbar2.

pchanged()

Call all of the registered callbacks.

This function is triggered internally when a property is changed.

pick(mouseevent)

Process a pick event.

Each child artist will fire a pick event if mouseevent is over the artist and the artist has picker set.

pickable()

Return whether the artist is pickable.

properties()

Return a dictionary of all the properties of the artist.

remove()

Remove the artist from the figure if possible.

The effect will not be visible until the figure is redrawn, e.g., with .FigureCanvasBase.draw_idle. Call ~.axes.Axes.relim to update the axes limits if desired.

Note: ~.axes.Axes.relim will not see collections even if the collection was added to the axes with autolim = True.

Note: there is no support for removing the artist’s legend entry.

remove_callback(oid)

Remove a callback based on its observer id.

See also

add_callback

set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, bbox_to_anchor=<UNSET>, child=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, gid=<UNSET>, height=<UNSET>, in_layout=<UNSET>, label=<UNSET>, offset=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, width=<UNSET>, zorder=<UNSET>)

Set multiple properties at once.

Supported properties are

Properties:

agg_filter: a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array alpha: scalar or None animated: bool bbox_to_anchor: unknown child: unknown clip_box: .Bbox clip_on: bool clip_path: Patch or (Path, Transform) or None figure: ~matplotlib.figure.Figure gid: str height: float in_layout: bool label: object offset: (float, float) or callable path_effects: .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 width: float zorder: float

set_agg_filter(filter_func)

Set the agg filter.

Parameters:

filter_func (callable) –

A filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array.

set_alpha(alpha)

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

Parameters:

alpha (scalar or None) – alpha must be within the 0-1 range, inclusive.

set_animated(b)

Set whether the artist is intended to be used in an animation.

If True, the artist is excluded from regular drawing of the figure. You have to call .Figure.draw_artist / .Axes.draw_artist explicitly on the artist. This appoach is used to speed up animations using blitting.

See also matplotlib.animation and /tutorials/advanced/blitting.

Parameters:

b (bool) –

set_bbox_to_anchor(bbox, transform=None)

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_child(child)

Set the child to be anchored.

set_clip_box(clipbox)

Set the artist’s clip .Bbox.

Parameters:

clipbox (.Bbox) –

set_clip_on(b)

Set whether the artist uses clipping.

When False artists will be visible outside of the axes which can lead to unexpected results.

Parameters:

b (bool) –

set_clip_path(path, transform=None)

Set the artist’s clip path.

Parameters:
  • path (.Patch or .Path or .TransformedPath or None) – The clip path. If given a .Path, transform must be provided as well. If None, a previously set clip path is removed.

  • transform (~matplotlib.transforms.Transform, optional) – Only used if path is a .Path, in which case the given .Path is converted to a .TransformedPath using transform.

Notes

For efficiency, if path is a .Rectangle this method will set the clipping box to the corresponding rectangle and set the clipping path to None.

For technical reasons (support of ~.Artist.set), a tuple (path, transform) is also accepted as a single positional parameter.

set_figure(fig)

Set the .Figure for the .OffsetBox and all its children.

Parameters:

fig (~matplotlib.figure.Figure) –

set_gid(gid)

Set the (group) id for the artist.

Parameters:

gid (str) –

set_height(height)

Set the height of the box.

Parameters:

height (float) –

set_in_layout(in_layout)

Set if artist is to be included in layout calculations, E.g. /tutorials/intermediate/constrainedlayout_guide, .Figure.tight_layout(), and fig.savefig(fname, bbox_inches='tight').

Parameters:

in_layout (bool) –

set_label(s)

Set a label that will be displayed in the legend.

Parameters:

s (object) – s will be converted to a string by calling str.

set_offset(xy)

Set the offset.

Parameters:

xy ((float, float) or callable) –

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_path_effects(path_effects)

Set the path effects.

Parameters:

path_effects (.AbstractPathEffect) –

set_picker(picker)

Define the picking behavior of the artist.

Parameters:

picker (None or bool or float or callable) –

This can be one of the following:

  • None: Picking is disabled for this artist (default).

  • A boolean: If True then picking will be enabled and the artist will fire a pick event if the mouse event is over the artist.

  • A float: If picker is a number it is interpreted as an epsilon tolerance in points and the artist will fire off an event if its data is within epsilon of the mouse event. For some artists like lines and patch collections, the artist may provide additional data to the pick event that is generated, e.g., the indices of the data within epsilon of the pick event

  • A function: If picker is callable, it is a user supplied function which determines whether the artist is hit by the mouse event:

    hit, props = picker(artist, mouseevent)
    

    to determine the hit test. if the mouse event is over the artist, return hit=True and props is a dictionary of properties you want added to the PickEvent attributes.

set_rasterized(rasterized)

Force rasterized (bitmap) drawing for vector graphics output.

Rasterized drawing is not supported by all artists. If you try to enable this on an artist that does not support it, the command has no effect and a warning will be issued.

This setting is ignored for pixel-based output.

See also /gallery/misc/rasterization_demo.

Parameters:

rasterized (bool) –

set_sketch_params(scale=None, length=None, randomness=None)

Set the sketch parameters.

Parameters:
  • scale (float, optional) – The amplitude of the wiggle perpendicular to the source line, in pixels. If scale is None, or not provided, no sketch filter will be provided.

  • length (float, optional) – The length of the wiggle along the line, in pixels (default 128.0)

  • randomness (float, optional) –

    The scale factor by which the length is shrunken or expanded (default 16.0)

    The PGF backend uses this argument as an RNG seed and not as described above. Using the same seed yields the same random shape.

set_snap(snap)

Set the snapping behavior.

Snapping aligns positions with the pixel grid, which results in clearer images. For example, if a black line of 1px width was defined at a position in between two pixels, the resulting image would contain the interpolated value of that line in the pixel grid, which would be a grey value on both adjacent pixel positions. In contrast, snapping will move the line to the nearest integer pixel value, so that the resulting image will really contain a 1px wide black line.

Snapping is currently only supported by the Agg and MacOSX backends.

Parameters:

snap (bool or None) –

Possible values:

  • True: Snap vertices to the nearest pixel center.

  • False: Do not modify vertex positions.

  • None: (auto) If the path contains only rectilinear line segments, round to the nearest pixel center.

set_transform(t)

Set the artist transform.

Parameters:

t (.Transform) –

set_url(url)

Set the url for the artist.

Parameters:

url (str) –

set_visible(b)

Set the artist’s visibility.

Parameters:

b (bool) –

set_width(width)

Set the width of the box.

Parameters:

width (float) –

set_zorder(level)

Set the zorder for the artist. Artists with lower zorder values are drawn first.

Parameters:

level (float) –

property stale

Whether the artist is ‘stale’ and needs to be re-drawn for the output to match the internal state of the artist.

property sticky_edges

x and y sticky edge lists for autoscaling.

When performing autoscaling, if a data limit coincides with a value in the corresponding sticky_edges list, then no margin will be added–the view limit “sticks” to the edge. A typical use case is histograms, where one usually expects no margin on the bottom edge (0) of the histogram.

Moreover, margin expansion “bumps” against sticky edges and cannot cross them. For example, if the upper data limit is 1.0, the upper view limit computed by simple margin application is 1.2, but there is a sticky edge at 1.1, then the actual upper view limit will be 1.1.

This attribute cannot be assigned to; however, the x and y lists can be modified in place as needed.

Examples

>>> artist.sticky_edges.x[:] = (xmin, xmax)
>>> artist.sticky_edges.y[:] = (ymin, ymax)
update(props)

Update this artist’s properties from the dict props.

Parameters:

props (dict) –

update_frame(bbox, fontsize=None)
update_from(other)

Copy properties from other to self.

zorder = 5