interactive_figure.interactive_figure#

This module provides functions to create and interact with a Matplotlib figure. The figure registers mouse presses, keyboard input and the location of the mouse after any input.

Source: teuncm/interactive-figure

Functions#

create([hide_labels, hide_toolbar])

Create the interactive figure.

draw()

Draw contents of the figure.

clear()

Reset contents and layout of the figure.

toggle_fullscreen()

Toggle fullscreen.

close()

Close the figure.

wait_for_interaction([timeout])

Wait for interaction.

get_last_key_press()

Get the last key press in lowercase.

get_last_mouse_press()

Get the ID of the last mouse press.

get_last_mouse_pos()

Get the last mouse position.

wait(timeout)

Freeze for the given number of seconds.

Module Contents#

create(hide_labels=False, hide_toolbar=False, **kwargs)#

Create the interactive figure.

Parameters#

hide_labelsbool, optional

remove all labels from the figure (makes rendering much faster).

hide_toolbarbool, optional

whether to hide the toolbar, default False.

Remaining keyword arguments will be sent to the figure upon creation.

Raises#

RuntimeError

if multiple interactive figures are created.

draw()#

Draw contents of the figure.

clear()#

Reset contents and layout of the figure.

toggle_fullscreen()#

Toggle fullscreen.

close()#

Close the figure.

wait_for_interaction(timeout=-1)#

Wait for interaction.

Optionally use a timeout in seconds.

Parameters#

timeoutint, optional

Timeout in seconds when waiting for input.

Returns#

bool | None
  • True if a key was pressed.

  • False if a mouse button was pressed.

  • None if no input was given within the timeout.

get_last_key_press()#

Get the last key press in lowercase.

Returns#

str | None

The last key that was pressed.

get_last_mouse_press()#

Get the ID of the last mouse press.

Returns#

int | None

The identifier of the last mouse button that was pressed.

get_last_mouse_pos()#

Get the last mouse position.

Returns#

(x: float, y: float) | (None, None)

The last registered mouse position after any interaction.

wait(timeout)#

Freeze for the given number of seconds.

During this period it is not possible to interact with the figure. For sub-second timeouts use time.wait() instead.

Parameters#

timeoutfloat

Number of seconds to wait for.