interactive_figure.interactive_figure#

This package contains functions to create and interact with a modified 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_x_labels, hide_y_labels, hide_top_frame, ...])

Create the interactive figure.

draw()

Draw contents of the figure canvas.

clear()

Clear the canvas, but don't draw() it.

toggle_fullscreen()

Toggle fullscreen on/off.

close()

Close the figure.

wait_for_interaction([timeout])

Wait for interaction.

get_last_key_press()

Get the last key press.

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_x_labels=False, hide_y_labels=False, hide_top_frame=False, hide_right_frame=False, hide_bottom_frame=False, hide_left_frame=False, hide_toolbar=False, layout='constrained', **kwargs)#

Create the interactive figure.

Parameters:
  • hide_x_labels (bool, optional) – Hide the x-axis labels, default False.

  • hide_y_labels (bool, optional) – Hide the y-axis labels, default False.

  • hide_top_frame (bool, optional) – Hide the top edge of the axes frame, default False.

  • hide_right_frame (bool, optional) – Hide the right edge of the axes frame, default False.

  • hide_bottom_frame (bool, optional) – Hide the bottom edge of the axes frame, default False.

  • hide_left_frame (bool, optional) – Hide the left edge of the axes frame, default False.

  • hide_toolbar (bool, optional) – Hide the toolbar, default False.

  • layout (str, optional) – The layout mode for the figure, default ‘constrained’. See: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.figure.html

  • Remaining keyword arguments will be sent to the Matplotlib figure.

Returns:

None

Raises:

RuntimeError – if multiple interactive figures are created at the same time.

draw()#

Draw contents of the figure canvas.

Parameters:

None

Returns:

None

clear()#

Clear the canvas, but don’t draw() it.

Parameters:

None

Returns:

None

toggle_fullscreen()#

Toggle fullscreen on/off.

Parameters:

None

Returns:

None

close()#

Close the figure.

Parameters:

None

Returns:

None

wait_for_interaction(timeout=-1)#

Wait for interaction.

Optionally use a timeout in seconds.

Parameters:

timeout (int, 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.

Parameters:

None

Returns:

str | None – The last key that was pressed.

get_last_mouse_press()#

Get the ID of the last mouse press.

Parameters:

None

Returns:

int | None – The identifier of the last mouse button that was pressed.

get_last_mouse_pos()#

Get the last mouse position.

Parameters:

None

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:

timeout (float) – Number of seconds to wait for.

Returns:

None