smpl_animation.animation.FigureCanvasAgg

class smpl_animation.animation.FigureCanvasAgg(figure=None)[source]

Bases: FigureCanvasBase

__init__(figure=None)

Methods

__init__([figure])

blit([bbox])

Blit the canvas in bbox (default entire canvas).

buffer_rgba()

Get the image as a memoryview to the renderer's buffer.

button_press_event(x, y, button[, dblclick, ...])

[Deprecated] Callback processing for mouse button press events.

button_release_event(x, y, button[, guiEvent])

[Deprecated] Callback processing for mouse button release events.

close_event([guiEvent])

[Deprecated] Pass a CloseEvent to all functions connected to close_event.

copy_from_bbox(bbox)

draw()

Render the .Figure.

draw_event(renderer)

[Deprecated] Pass a DrawEvent to all functions connected to draw_event.

draw_idle(*args, **kwargs)

Request a widget redraw once control returns to the GUI event loop.

enter_notify_event([guiEvent, xy])

[Deprecated] Callback processing for the mouse cursor entering the canvas.

flush_events()

Flush the GUI events for the figure.

get_default_filename()

Return a string, which includes extension, suitable for use as a default filename.

get_default_filetype()

Return the default savefig file format as specified in :rc:`savefig.format`.

get_renderer([cleared])

get_supported_filetypes()

Return dict of savefig file formats supported by this backend.

get_supported_filetypes_grouped()

Return a dict of savefig file formats supported by this backend, where the keys are a file type name, such as 'Joint Photographic Experts Group', and the values are a list of filename extensions used for that filetype, such as ['jpg', 'jpeg'].

get_width_height(*[, physical])

Return the figure width and height in integral points or pixels.

grab_mouse(ax)

Set the child ~.axes.Axes which is grabbing the mouse events.

inaxes(xy)

Return the topmost visible ~.axes.Axes containing the point xy.

is_saving()

Return whether the renderer is in the process of saving to a file, rather than rendering for an on-screen buffer.

key_press_event(key[, guiEvent])

[Deprecated] Pass a KeyEvent to all functions connected to key_press_event.

key_release_event(key[, guiEvent])

[Deprecated] Pass a KeyEvent to all functions connected to key_release_event.

leave_notify_event([guiEvent])

[Deprecated] Callback processing for the mouse cursor leaving the canvas.

motion_notify_event(x, y[, guiEvent])

[Deprecated] Callback processing for mouse movement events.

mpl_connect(s, func)

Bind function func to event s.

mpl_disconnect(cid)

Disconnect the callback with id cid.

new_manager(figure, num)

Create a new figure manager for figure, using this canvas class.

new_timer([interval, callbacks])

Create a new backend-specific subclass of .Timer.

pick(mouseevent)

[Deprecated]

pick_event(mouseevent, artist, **kwargs)

[Deprecated] Callback processing for pick events.

print_figure(filename[, dpi, facecolor, ...])

Render the figure to hardcopy.

print_jpeg(filename_or_obj, *args[, pil_kwargs])

Write the figure to a JPEG file.

print_jpg(filename_or_obj, *args[, pil_kwargs])

Write the figure to a JPEG file.

print_png(filename_or_obj, *args[, ...])

Write the figure to a PNG file.

print_raw(filename_or_obj, *args)

print_rgba(filename_or_obj, *args)

print_tif(filename_or_obj, *[, pil_kwargs])

Write the figure to a TIFF file.

print_tiff(filename_or_obj, *[, pil_kwargs])

Write the figure to a TIFF file.

print_to_buffer()

print_webp(filename_or_obj, *[, pil_kwargs])

Write the figure to a WebP file.

release_mouse(ax)

Release the mouse grab held by the ~.axes.Axes ax.

resize(w, h)

UNUSED: Set the canvas size in pixels.

resize_event()

[Deprecated] Pass a ResizeEvent to all functions connected to resize_event.

restore_region(region[, bbox, xy])

scroll_event(x, y, step[, guiEvent])

[Deprecated] Callback processing for scroll events.

set_cursor(cursor)

Set the current cursor.

start_event_loop([timeout])

Start a blocking event loop.

stop_event_loop()

Stop the current blocking event loop.

switch_backends(FigureCanvasClass)

Instantiate an instance of FigureCanvasClass

tostring_argb()

Get the image as ARGB bytes.

tostring_rgb()

Get the image as RGB bytes.

Attributes

button_pick_id

callbacks

device_pixel_ratio

The ratio of physical to logical pixels used for the canvas on screen.

events

filetypes

fixed_dpi

required_interactive_framework

scroll_pick_id

supports_blit

blit(bbox=None)

Blit the canvas in bbox (default entire canvas).

buffer_rgba()[source]

Get the image as a memoryview to the renderer’s buffer.

draw must be called at least once before this function will work and to update the renderer for any subsequent changes to the Figure.

button_press_event(x, y, button, dblclick=False, guiEvent=None)

[Deprecated] Callback processing for mouse button press events.

Backend derived classes should call this function on any mouse button press. (x, y) are the canvas coords ((0, 0) is lower left). button and key are as defined in MouseEvent.

This method will call all functions connected to the ‘button_press_event’ with a MouseEvent instance.

Notes

Deprecated since version 3.6: Use callbacks.process(‘button_press_event’, MouseEvent(…)) instead.

button_release_event(x, y, button, guiEvent=None)

[Deprecated] Callback processing for mouse button release events.

Backend derived classes should call this function on any mouse button release.

This method will call all functions connected to the ‘button_release_event’ with a MouseEvent instance.

Parameters

xfloat

The canvas coordinates where 0=left.

yfloat

The canvas coordinates where 0=bottom.

guiEvent

The native UI event that generated the Matplotlib event.

Notes

Deprecated since version 3.6: Use callbacks.process(‘button_release_event’, MouseEvent(…)) instead.

close_event(guiEvent=None)

[Deprecated] Pass a CloseEvent to all functions connected to close_event.

Notes

Deprecated since version 3.6: Use callbacks.process(‘close_event’, CloseEvent(…)) instead.

property device_pixel_ratio

The ratio of physical to logical pixels used for the canvas on screen.

By default, this is 1, meaning physical and logical pixels are the same size. Subclasses that support High DPI screens may set this property to indicate that said ratio is different. All Matplotlib interaction, unless working directly with the canvas, remains in logical pixels.

draw()[source]

Render the .Figure.

This method must walk the artist tree, even if no output is produced, because it triggers deferred work that users may want to access before saving output to disk. For example computing limits, auto-limits, and tick values.

draw_event(renderer)

[Deprecated] Pass a DrawEvent to all functions connected to draw_event.

Notes

Deprecated since version 3.6: Use callbacks.process(‘draw_event’, DrawEvent(…)) instead.

draw_idle(*args, **kwargs)

Request a widget redraw once control returns to the GUI event loop.

Even if multiple calls to draw_idle occur before control returns to the GUI event loop, the figure will only be rendered once.

Notes

Backends may choose to override the method and implement their own strategy to prevent multiple renderings.

enter_notify_event(guiEvent=None, xy=None)

[Deprecated] Callback processing for the mouse cursor entering the canvas.

Backend derived classes should call this function when entering canvas.

Parameters

guiEvent

The native UI event that generated the Matplotlib event.

xy(float, float)

The coordinate location of the pointer when the canvas is entered.

Notes

Deprecated since version 3.6: Use callbacks.process(‘enter_notify_event’, LocationEvent(…)) instead.

flush_events()

Flush the GUI events for the figure.

Interactive backends need to reimplement this method.

get_default_filename()

Return a string, which includes extension, suitable for use as a default filename.

classmethod get_default_filetype()

Return the default savefig file format as specified in :rc:`savefig.format`.

The returned string does not include a period. This method is overridden in backends that only support a single file type.

classmethod get_supported_filetypes()

Return dict of savefig file formats supported by this backend.

classmethod get_supported_filetypes_grouped()

Return a dict of savefig file formats supported by this backend, where the keys are a file type name, such as ‘Joint Photographic Experts Group’, and the values are a list of filename extensions used for that filetype, such as [‘jpg’, ‘jpeg’].

get_width_height(*, physical=False)

Return the figure width and height in integral points or pixels.

When the figure is used on High DPI screens (and the backend supports it), the truncation to integers occurs after scaling by the device pixel ratio.

Parameters

physicalbool, default: False

Whether to return true physical pixels or logical pixels. Physical pixels may be used by backends that support HiDPI, but still configure the canvas using its actual size.

Returns

width, heightint

The size of the figure, in points or pixels, depending on the backend.

grab_mouse(ax)

Set the child ~.axes.Axes which is grabbing the mouse events.

Usually called by the widgets themselves. It is an error to call this if the mouse is already grabbed by another Axes.

inaxes(xy)

Return the topmost visible ~.axes.Axes containing the point xy.

Parameters

xy(float, float)

(x, y) pixel positions from left/bottom of the canvas.

Returns

~matplotlib.axes.Axes or None

The topmost visible Axes containing the point, or None if there is no Axes at the point.

is_saving()

Return whether the renderer is in the process of saving to a file, rather than rendering for an on-screen buffer.

key_press_event(key, guiEvent=None)

[Deprecated] Pass a KeyEvent to all functions connected to key_press_event.

Notes

Deprecated since version 3.6: Use callbacks.process(‘key_press_event’, KeyEvent(…)) instead.

key_release_event(key, guiEvent=None)

[Deprecated] Pass a KeyEvent to all functions connected to key_release_event.

Notes

Deprecated since version 3.6: Use callbacks.process(‘key_release_event’, KeyEvent(…)) instead.

leave_notify_event(guiEvent=None)

[Deprecated] Callback processing for the mouse cursor leaving the canvas.

Backend derived classes should call this function when leaving canvas.

Parameters

guiEvent

The native UI event that generated the Matplotlib event.

Notes

Deprecated since version 3.6: Use callbacks.process(‘leave_notify_event’, LocationEvent(…)) instead.

manager_class

alias of FigureManagerBase

motion_notify_event(x, y, guiEvent=None)

[Deprecated] Callback processing for mouse movement events.

Backend derived classes should call this function on any motion-notify-event.

This method will call all functions connected to the ‘motion_notify_event’ with a MouseEvent instance.

Parameters

xfloat

The canvas coordinates where 0=left.

yfloat

The canvas coordinates where 0=bottom.

guiEvent

The native UI event that generated the Matplotlib event.

Notes

Deprecated since version 3.6: Use callbacks.process(‘motion_notify_event’, MouseEvent(…)) instead.

mpl_connect(s, func)

Bind function func to event s.

Parameters

sstr

One of the following events ids:

  • ‘button_press_event’

  • ‘button_release_event’

  • ‘draw_event’

  • ‘key_press_event’

  • ‘key_release_event’

  • ‘motion_notify_event’

  • ‘pick_event’

  • ‘resize_event’

  • ‘scroll_event’

  • ‘figure_enter_event’,

  • ‘figure_leave_event’,

  • ‘axes_enter_event’,

  • ‘axes_leave_event’

  • ‘close_event’.

funccallable

The callback function to be executed, which must have the signature:

def func(event: Event) -> Any

For the location events (button and key press/release), if the mouse is over the Axes, the inaxes attribute of the event will be set to the ~matplotlib.axes.Axes the event occurs is over, and additionally, the variables xdata and ydata attributes will be set to the mouse location in data coordinates. See .KeyEvent and .MouseEvent for more info.

Returns

cid

A connection id that can be used with .FigureCanvasBase.mpl_disconnect.

Examples

def on_press(event):
    print('you pressed', event.button, event.xdata, event.ydata)

cid = canvas.mpl_connect('button_press_event', on_press)
mpl_disconnect(cid)

Disconnect the callback with id cid.

Examples

cid = canvas.mpl_connect('button_press_event', on_press)
# ... later
canvas.mpl_disconnect(cid)
classmethod new_manager(figure, num)

Create a new figure manager for figure, using this canvas class.

Notes

This method should not be reimplemented in subclasses. If custom manager creation logic is needed, please reimplement FigureManager.create_with_canvas.

new_timer(interval=None, callbacks=None)

Create a new backend-specific subclass of .Timer.

This is useful for getting periodic events through the backend’s native event loop. Implemented only for backends with GUIs.

Parameters

intervalint

Timer interval in milliseconds.

callbackslist[tuple[callable, tuple, dict]]

Sequence of (func, args, kwargs) where func(*args, **kwargs) will be executed by the timer every interval.

Callbacks which return False or 0 will be removed from the timer.

Examples

>>> timer = fig.canvas.new_timer(callbacks=[(f1, (1,), {'a': 3})])
pick(mouseevent)

[Deprecated]

Notes

Deprecated since version 3.6: Use canvas.figure.pick instead.

pick_event(mouseevent, artist, **kwargs)

[Deprecated] Callback processing for pick events.

This method will be called by artists who are picked and will fire off PickEvent callbacks registered listeners.

Note that artists are not pickable by default (see .Artist.set_picker).

Notes

Deprecated since version 3.6: Use callbacks.process(‘pick_event’, PickEvent(…)) instead.

print_figure(filename, dpi=None, facecolor=None, edgecolor=None, orientation='portrait', format=None, *, bbox_inches=None, pad_inches=None, bbox_extra_artists=None, backend=None, **kwargs)

Render the figure to hardcopy. Set the figure patch face and edge colors. This is useful because some of the GUIs have a gray figure face color background and you’ll probably want to override this on hardcopy.

Parameters

filenamestr or path-like or file-like

The file where the figure is saved.

dpifloat, default: :rc:`savefig.dpi`

The dots per inch to save the figure in.

facecolorcolor or ‘auto’, default: :rc:`savefig.facecolor`

The facecolor of the figure. If ‘auto’, use the current figure facecolor.

edgecolorcolor or ‘auto’, default: :rc:`savefig.edgecolor`

The edgecolor of the figure. If ‘auto’, use the current figure edgecolor.

orientation{‘landscape’, ‘portrait’}, default: ‘portrait’

Only currently applies to PostScript printing.

formatstr, optional

Force a specific file format. If not given, the format is inferred from the filename extension, and if that fails from :rc:`savefig.format`.

bbox_inches‘tight’ or .Bbox, default: :rc:`savefig.bbox`

Bounding box in inches: only the given portion of the figure is saved. If ‘tight’, try to figure out the tight bbox of the figure.

pad_inchesfloat, default: :rc:`savefig.pad_inches`

Amount of padding around the figure when bbox_inches is ‘tight’.

bbox_extra_artistslist of ~matplotlib.artist.Artist, optional

A list of extra artists that will be considered when the tight bbox is calculated.

backendstr, optional

Use a non-default backend to render the file, e.g. to render a png file with the “cairo” backend rather than the default “agg”, or a pdf file with the “pgf” backend rather than the default “pdf”. Note that the default backend is normally sufficient. See the-builtin-backends for a list of valid backends for each file format. Custom backends can be referenced as “module://…”.

print_jpeg(filename_or_obj, *args, pil_kwargs=None)

Write the figure to a JPEG file.

Parameters

filename_or_objstr or path-like or file-like

The file to write to.

pil_kwargsdict, optional

Additional keyword arguments that are passed to PIL.Image.Image.save when saving the figure.

print_jpg(filename_or_obj, *args, pil_kwargs=None)[source]

Write the figure to a JPEG file.

Parameters

filename_or_objstr or path-like or file-like

The file to write to.

pil_kwargsdict, optional

Additional keyword arguments that are passed to PIL.Image.Image.save when saving the figure.

print_png(filename_or_obj, *args, metadata=None, pil_kwargs=None)[source]

Write the figure to a PNG file.

Parameters

filename_or_objstr or path-like or file-like

The file to write to.

metadatadict, optional

Metadata in the PNG file as key-value pairs of bytes or latin-1 encodable strings. According to the PNG specification, keys must be shorter than 79 chars.

The PNG specification defines some common keywords that may be used as appropriate:

  • Title: Short (one line) title or caption for image.

  • Author: Name of image’s creator.

  • Description: Description of image (possibly long).

  • Copyright: Copyright notice.

  • Creation Time: Time of original image creation (usually RFC 1123 format).

  • Software: Software used to create the image.

  • Disclaimer: Legal disclaimer.

  • Warning: Warning of nature of content.

  • Source: Device used to create the image.

  • Comment: Miscellaneous comment; conversion from other image format.

Other keywords may be invented for other purposes.

If ‘Software’ is not given, an autogenerated value for Matplotlib will be used. This can be removed by setting it to None.

For more details see the PNG specification.

pil_kwargsdict, optional

Keyword arguments passed to PIL.Image.Image.save.

If the ‘pnginfo’ key is present, it completely overrides metadata, including the default ‘Software’ key.

print_tif(filename_or_obj, *, pil_kwargs=None)[source]

Write the figure to a TIFF file.

Parameters

filename_or_objstr or path-like or file-like

The file to write to.

pil_kwargsdict, optional

Additional keyword arguments that are passed to PIL.Image.Image.save when saving the figure.

print_tiff(filename_or_obj, *, pil_kwargs=None)

Write the figure to a TIFF file.

Parameters

filename_or_objstr or path-like or file-like

The file to write to.

pil_kwargsdict, optional

Additional keyword arguments that are passed to PIL.Image.Image.save when saving the figure.

print_webp(filename_or_obj, *, pil_kwargs=None)[source]

Write the figure to a WebP file.

Parameters

filename_or_objstr or path-like or file-like

The file to write to.

pil_kwargsdict, optional

Additional keyword arguments that are passed to PIL.Image.Image.save when saving the figure.

release_mouse(ax)

Release the mouse grab held by the ~.axes.Axes ax.

Usually called by the widgets. It is ok to call this even if ax doesn’t have the mouse grab currently.

resize(w, h)

UNUSED: Set the canvas size in pixels.

Certain backends may implement a similar method internally, but this is not a requirement of, nor is it used by, Matplotlib itself.

resize_event()

[Deprecated] Pass a ResizeEvent to all functions connected to resize_event.

Notes

Deprecated since version 3.6: Use callbacks.process(‘resize_event’, ResizeEvent(…)) instead.

scroll_event(x, y, step, guiEvent=None)

[Deprecated] Callback processing for scroll events.

Backend derived classes should call this function on any scroll wheel event. (x, y) are the canvas coords ((0, 0) is lower left). button and key are as defined in MouseEvent.

This method will call all functions connected to the ‘scroll_event’ with a MouseEvent instance.

Notes

Deprecated since version 3.6: Use callbacks.process(‘scroll_event’, MouseEvent(…)) instead.

set_cursor(cursor)

Set the current cursor.

This may have no effect if the backend does not display anything.

If required by the backend, this method should trigger an update in the backend event loop after the cursor is set, as this method may be called e.g. before a long-running task during which the GUI is not updated.

Parameters

cursor.Cursors

The cursor to display over the canvas. Note: some backends may change the cursor for the entire window.

start_event_loop(timeout=0)

Start a blocking event loop.

Such an event loop is used by interactive functions, such as ~.Figure.ginput and ~.Figure.waitforbuttonpress, to wait for events.

The event loop blocks until a callback function triggers stop_event_loop, or timeout is reached.

If timeout is 0 or negative, never timeout.

Only interactive backends need to reimplement this method and it relies on flush_events being properly implemented.

Interactive backends should implement this in a more native way.

stop_event_loop()

Stop the current blocking event loop.

Interactive backends need to reimplement this to match start_event_loop

switch_backends(FigureCanvasClass)

Instantiate an instance of FigureCanvasClass

This is used for backend switching, e.g., to instantiate a FigureCanvasPS from a FigureCanvasGTK. Note, deep copying is not done, so any changes to one of the instances (e.g., setting figure size or line props), will be reflected in the other

tostring_argb()[source]

Get the image as ARGB bytes.

draw must be called at least once before this function will work and to update the renderer for any subsequent changes to the Figure.

tostring_rgb()[source]

Get the image as RGB bytes.

draw must be called at least once before this function will work and to update the renderer for any subsequent changes to the Figure.