smpl.plot2d.NonUniformImage

class smpl.plot2d.NonUniformImage(ax, *, interpolation='nearest', **kwargs)[source]

Bases: AxesImage

__init__(ax, *, interpolation='nearest', **kwargs)[source]

Parameters

interpolation : {‘nearest’, ‘bilinear’}, default: ‘nearest’

**kwargs

All other keyword arguments are identical to those of .AxesImage.

Methods

__init__(ax, *[, interpolation])

Parameters interpolation : {'nearest', 'bilinear'}, default: 'nearest'

add_callback(func)

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

autoscale()

Autoscale the scalar limits on the norm instance using the current array

autoscale_None()

Autoscale the scalar limits on the norm instance using the current array, changing only limits that are None

can_composite()

Return whether the image can be composited with its neighbors.

changed()

Call this whenever the mappable is changed so observers can update.

contains(mouseevent)

Test whether the mouse event occurred within the image.

convert_xunits(x)

Convert x using the unit type of the xaxis.

convert_yunits(y)

Convert y using the unit type of the yaxis.

draw(renderer, *args, **kwargs)

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

findobj([match, include_self])

Find artist objects.

format_cursor_data(data)

Return a string representation of 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_array()

Return the array of values, that are mapped to colors.

get_children()

Return a list of the child .Artists of this .Artist.

get_clim()

Return the values (min, max) that are mapped to the colormap limits.

get_clip_box()

Return the clipbox.

get_clip_on()

Return whether the artist uses clipping.

get_clip_path()

Return the clip path.

get_cmap()

Return the .Colormap instance.

get_cursor_data(event)

Return the image value at the event position or None if the event is outside the image.

get_extent()

Return the image extent as tuple (left, right, bottom, top).

get_figure()

Return the .Figure instance the artist belongs to.

get_filternorm()

Return whether the resize filter normalizes the weights.

get_filterrad()

Return the filterrad setting.

get_gid()

Return the group id.

get_in_layout()

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

get_interpolation()

Return the interpolation method the image uses when resizing.

get_label()

Return the label used for this artist in the legend.

get_mouseover()

Return whether this artist is queried for custom context information when the mouse cursor moves over it.

get_path_effects()

get_picker()

Return the picking behavior of the artist.

get_rasterized()

Return whether the artist is to be rasterized.

get_resample()

Return whether image resampling is used.

get_size()

Return the size of the image as tuple (numrows, numcols).

get_sketch_params()

Return the sketch parameters for the artist.

get_snap()

Return the snap setting.

get_tightbbox([renderer])

Like .Artist.get_window_extent, but includes any clipping.

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_window_extent([renderer])

Get the artist's bounding box in display space.

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.

make_image(renderer[, magnification, unsampled])

Normalize, rescale, and colormap this image's data for rendering using renderer, with the given magnification.

pchanged()

Call all of the registered callbacks.

pick(mouseevent)

Process a pick event.

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.

remove_callback(oid)

Remove a callback based on its observer id.

set(*[, agg_filter, alpha, animated, array, ...])

Set multiple properties at once.

set_agg_filter(filter_func)

Set the agg filter.

set_alpha(alpha)

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

set_animated(b)

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

set_array(*args)

Retained for backwards compatibility - use set_data instead.

set_clim([vmin, vmax])

Set the norm limits for image scaling.

set_clip_box(clipbox)

Set the artist's clip .Bbox.

set_clip_on(b)

Set whether the artist uses clipping.

set_clip_path(path[, transform])

Set the artist's clip path.

set_cmap(cmap)

Set the colormap for luminance data.

set_data(x, y, A)

Set the grid for the pixel centers, and the pixel values.

set_extent(extent)

Set the image extent.

set_figure(fig)

Set the .Figure instance the artist belongs to.

set_filternorm(s)

Set whether the resize filter normalizes the weights.

set_filterrad(s)

Set the resize filter radius only applicable to some interpolation schemes -- see help for imshow

set_gid(gid)

Set the (group) id for the artist.

set_in_layout(in_layout)

Set if artist is to be included in layout calculations, E.g.

set_interpolation(s)

Parameters s {'nearest', 'bilinear'} or None If None, use :rc:`image.interpolation`. :4: (INFO/1) No role entry for "rc" in module "docutils.parsers.rst.languages.en". Trying "rc" as canonical role name. :4: (ERROR/3) Unknown interpreted text role "rc".

set_interpolation_stage(s)

Set when interpolation happens during the transform to RGBA.

set_label(s)

Set a label that will be displayed in the legend.

set_mouseover(mouseover)

Set whether this artist is queried for custom context information when the mouse cursor moves over it.

set_norm(norm)

Set the normalization instance.

set_path_effects(path_effects)

Set the path effects.

set_picker(picker)

Define the picking behavior of the artist.

set_rasterized(rasterized)

Force rasterized (bitmap) drawing for vector graphics output.

set_resample(v)

Set whether image resampling is used.

set_sketch_params([scale, length, randomness])

Set the sketch parameters.

set_snap(snap)

Set the snapping behavior.

set_transform(t)

Set the artist transform.

set_url(url)

Set the url for the artist.

set_visible(b)

Set the artist's visibility.

set_zorder(level)

Set the zorder for the artist.

to_rgba(x[, alpha, bytes, norm])

Return a normalized rgba array corresponding to x.

update(props)

Update this artist's properties from the dict props.

update_from(other)

Copy properties from other to self.

write_png(fname)

Write the image to png file fname.

Attributes

axes

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

callbacksSM

mouseover

norm

stale

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

sticky_edges

x and y sticky edge lists for autoscaling.

zorder

add_callback(func)

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

Parameters

funccallable

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

int

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

See Also

remove_callback

autoscale()

Autoscale the scalar limits on the norm instance using the current array

autoscale_None()

Autoscale the scalar limits on the norm instance using the current array, changing only limits that are None

property axes

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

can_composite()

Return whether the image can be composited with its neighbors.

changed()

Call this whenever the mappable is changed so observers can update.

colorbar

The last colorbar associated with this ScalarMappable. May be None.

contains(mouseevent)

Test whether the mouse event occurred within the image.

convert_xunits(x)

Convert x using the unit type of the xaxis.

If the artist is not 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 contained in an Axes or if the yaxis does not have units, y itself is returned.

draw(renderer, *args, **kwargs)

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

renderer : .RendererBase subclass.

Notes

This method is overridden in the Artist subclasses.

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_selfbool

Include self in the list to be checked for a match.

Returns

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_array()

Return the array of values, that are mapped to colors.

The base class .ScalarMappable does not make any assumptions on the dimensionality and shape of the array.

get_children()

Return a list of the child .Artists of this .Artist.

get_clim()

Return the values (min, max) that are mapped to the colormap limits.

get_clip_box()

Return the clipbox.

get_clip_on()

Return whether the artist uses clipping.

get_clip_path()

Return the clip path.

get_cmap()

Return the .Colormap instance.

get_cursor_data(event)

Return the image value at the event position or None if the event is outside the image.

See Also

matplotlib.artist.Artist.get_cursor_data

get_extent()[source]

Return the image extent as tuple (left, right, bottom, top).

get_figure()

Return the .Figure instance the artist belongs to.

get_filternorm()

Return whether the resize filter normalizes the weights.

get_filterrad()

Return the filterrad setting.

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_interpolation()

Return the interpolation method the image uses when resizing.

One of ‘antialiased’, ‘nearest’, ‘bilinear’, ‘bicubic’, ‘spline16’, ‘spline36’, ‘hanning’, ‘hamming’, ‘hermite’, ‘kaiser’, ‘quadric’, ‘catrom’, ‘gaussian’, ‘bessel’, ‘mitchell’, ‘sinc’, ‘lanczos’, or ‘none’.

get_label()

Return the label used for this artist in the legend.

get_mouseover()

Return whether this artist is queried for custom context information when the mouse cursor moves over it.

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_resample()

Return whether image resampling is used.

get_size()

Return the size of the image as tuple (numrows, numcols).

get_sketch_params()

Return the sketch parameters for the artist.

Returns

tuple or None

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.

get_snap()

Return the snap setting.

See .set_snap for details.

get_tightbbox(renderer=None)

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

.Bbox

The enclosing bounding box (in figure pixel coordinates).

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_window_extent(renderer=None)

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.

make_image(renderer, magnification=1.0, unsampled=False)[source]

Normalize, rescale, and colormap this image’s data for rendering using renderer, with the given magnification.

If unsampled is True, the image will not be scaled, but an appropriate affine transformation will be returned instead.

Returns

image(M, N, 4) uint8 array

The RGBA image, resampled unless unsampled is True.

x, yfloat

The upper left corner where the image should be drawn, in pixel space.

transAffine2D

The affine transformation from image to pixel space.

pchanged()

Call all of the registered callbacks.

This function is triggered internally when a property is changed.

See Also

add_callback remove_callback

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.

See Also

set_picker, get_picker, pickable

pickable()

Return whether the artist is pickable.

See Also

set_picker, get_picker, pick

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>, array=<UNSET>, clim=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, cmap=<UNSET>, data=<UNSET>, extent=<UNSET>, filternorm=<UNSET>, filterrad=<UNSET>, gid=<UNSET>, in_layout=<UNSET>, interpolation=<UNSET>, interpolation_stage=<UNSET>, label=<UNSET>, mouseover=<UNSET>, norm=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, resample=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<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 and two offsets from the bottom left corner of the image alpha: float or 2D array-like or None animated: bool array: unknown clim: (vmin: float, vmax: float) clip_box: .Bbox clip_on: bool clip_path: Patch or (Path, Transform) or None cmap: unknown data: unknown extent: 4-tuple of float figure: .Figure filternorm: unknown filterrad: unknown gid: str in_layout: bool interpolation: {‘nearest’, ‘bilinear’} or None interpolation_stage: {‘data’, ‘rgba’} or None label: object mouseover: bool norm: unknown path_effects: .AbstractPathEffect picker: None or bool or float or callable rasterized: bool resample: bool or None sketch_params: (scale: float, length: float, randomness: float) snap: bool or None transform: .Transform url: str visible: bool zorder: float

set_agg_filter(filter_func)

Set the agg filter.

Parameters

filter_funccallable

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

set_alpha(alpha)

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

Parameters

alpha : float or 2D array-like or None

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 approach is used to speed up animations using blitting.

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

Parameters

b : bool

set_array(*args)[source]

Retained for backwards compatibility - use set_data instead.

Parameters

A : array-like

set_clim(vmin=None, vmax=None)

Set the norm limits for image scaling.

Parameters

vmin, vmaxfloat

The limits.

The limits may also be passed as a tuple (vmin, vmax) as a single positional argument.

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_cmap(cmap)[source]

Set the colormap for luminance data.

Parameters

cmap : .Colormap or str or None

set_data(x, y, A)[source]

Set the grid for the pixel centers, and the pixel values.

Parameters

x, y1D array-like

Monotonic arrays of shapes (N,) and (M,), respectively, specifying pixel centers.

Aarray-like

(M, N) ndarray or masked array of values to be colormapped, or (M, N, 3) RGB array, or (M, N, 4) RGBA array.

set_extent(extent)

Set the image extent.

Parameters

extent4-tuple of float

The position and size of the image as tuple (left, right, bottom, top) in data coordinates.

Notes

This updates ax.dataLim, and, if autoscaling, sets ax.viewLim to tightly fit the image, regardless of dataLim. Autoscaling state is not changed, so following this with ax.autoscale_view() will redo the autoscaling in accord with dataLim.

set_figure(fig)

Set the .Figure instance the artist belongs to.

Parameters

fig : .Figure

set_filternorm(s)[source]

Set whether the resize filter normalizes the weights.

See help for ~.Axes.imshow.

Parameters

filternorm : bool

set_filterrad(s)[source]

Set the resize filter radius only applicable to some interpolation schemes – see help for imshow

Parameters

filterrad : positive float

set_gid(gid)

Set the (group) id for the artist.

Parameters

gid : str

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_interpolation(s)[source]

Parameters

s{‘nearest’, ‘bilinear’} or None

If None, use :rc:`image.interpolation`.

set_interpolation_stage(s)

Set when interpolation happens during the transform to RGBA.

Parameters

s{‘data’, ‘rgba’} or None

Whether to apply up/downsampling interpolation in data or rgba space.

set_label(s)

Set a label that will be displayed in the legend.

Parameters

sobject

s will be converted to a string by calling str.

set_mouseover(mouseover)

Set whether this artist is queried for custom context information when the mouse cursor moves over it.

Parameters

mouseover : bool

See Also

get_cursor_data .ToolCursorPosition .NavigationToolbar2

set_norm(norm)[source]

Set the normalization instance.

Parameters

norm : .Normalize or str or None

Notes

If there are any colorbars using the mappable for this norm, setting the norm of the mappable will reset the norm, locator, and formatters on the colorbar to default.

set_path_effects(path_effects)

Set the path effects.

Parameters

path_effects : .AbstractPathEffect

set_picker(picker)

Define the picking behavior of the artist.

Parameters

pickerNone 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_resample(v)

Set whether image resampling is used.

Parameters

vbool or None

If None, use :rc:`image.resample`.

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

Set the sketch parameters.

Parameters

scalefloat, 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.

lengthfloat, optional

The length of the wiggle along the line, in pixels (default 128.0)

randomnessfloat, 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

snapbool 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_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)
to_rgba(x, alpha=None, bytes=False, norm=True)

Return a normalized rgba array corresponding to x.

In the normal case, x is a 1D or 2D sequence of scalars, and the corresponding ndarray of rgba values will be returned, based on the norm and colormap set for this ScalarMappable.

There is one special case, for handling images that are already rgb or rgba, such as might have been read from an image file. If x is an ndarray with 3 dimensions, and the last dimension is either 3 or 4, then it will be treated as an rgb or rgba array, and no mapping will be done. The array can be uint8, or it can be floating point with values in the 0-1 range; otherwise a ValueError will be raised. If it is a masked array, the mask will be ignored. If the last dimension is 3, the alpha kwarg (defaulting to 1) will be used to fill in the transparency. If the last dimension is 4, the alpha kwarg is ignored; it does not replace the preexisting alpha. A ValueError will be raised if the third dimension is other than 3 or 4.

In either case, if bytes is False (default), the rgba array will be floats in the 0-1 range; if it is True, the returned rgba array will be uint8 in the 0 to 255 range.

If norm is False, no normalization of the input data is performed, and it is assumed to be in the range (0-1).

update(props)

Update this artist’s properties from the dict props.

Parameters

props : dict

update_from(other)

Copy properties from other to self.

write_png(fname)

Write the image to png file fname.