mpltoolbox.Tool#

class mpltoolbox.Tool(ax, spawner, *, autostart=True, on_create=None, on_remove=None, on_change=None, on_vertex_press=None, on_vertex_move=None, on_vertex_release=None, on_drag_press=None, on_drag_move=None, on_drag_release=None, enable_drag=True, enable_remove=True, enable_vertex_move=True, **kwargs)[source]#

A tool for creating and manipulating artists on a matplotlib figure. This is the base class for all tools in mpltoolbox.

Parameters:
  • ax (Axes) – The axes to which the tool is attached.

  • spawner – An object constructor that creates the artists.

  • autostart (bool, default: True) – If True, the tool is activated immediately.

  • on_create (Optional[Callable], default: None) – A function to be called when a new artist is created.

  • on_remove (Optional[Callable], default: None) – A function to be called when an artist is removed.

  • on_change (Optional[Callable], default: None) – A function to be called when an artist is changed.

  • on_vertex_press (Optional[Callable], default: None) – A function to be called when a vertex is pressed.

  • on_vertex_move (Optional[Callable], default: None) – A function to be called when a vertex is moved.

  • on_vertex_release (Optional[Callable], default: None) – A function to be called when a vertex is released.

  • on_drag_press (Optional[Callable], default: None) – A function to be called when an artist is dragged.

  • on_drag_move (Optional[Callable], default: None) – A function to be called when an artist is moved.

  • on_drag_release (Optional[Callable], default: None) – A function to be called when an artist is released.

  • enable_drag (bool | str, default: True) – If True, dragging the artists is enabled. If ‘xonly’ or ‘yonly’, dragging is restricted to the x or y direction, respectively. If False, dragging is disabled.

  • enable_remove (bool | str, default: True) – If True, removing the artists is enabled.

  • enable_vertex_move (bool | str, default: True) – If True, moving the vertices of the artists is enabled. If ‘xonly’ or ‘yonly’, moving is restricted to the x or y direction, respectively. If False, moving vertices is disabled.

  • kwargs – Additional keyword arguments for the artist constructor.

__init__(ax, spawner, *, autostart=True, on_create=None, on_remove=None, on_change=None, on_vertex_press=None, on_vertex_move=None, on_vertex_release=None, on_drag_press=None, on_drag_move=None, on_drag_release=None, enable_drag=True, enable_remove=True, enable_vertex_move=True, **kwargs)[source]#

Methods

__init__(ax, spawner, *[, autostart, ...])

call_on_change(event)

call_on_create(event)

call_on_drag_move(event)

call_on_drag_press(event)

call_on_drag_release(event)

call_on_remove(event)

call_on_vertex_move(event)

call_on_vertex_press(event)

call_on_vertex_release(event)

clear()

Remove all children from the axes.

click(x[, y, button, modifiers])

Simulate a click on the figure.

freeze()

Deactivate the tool but keep the children.

on_change(func)

on_create(func)

on_drag_move(func)

on_drag_press(func)

on_drag_release(func)

on_remove(func)

on_vertex_move(func)

on_vertex_press(func)

on_vertex_release(func)

remove(child)

Remove an artist from the figure.

shutdown()

Deactivate the tool and remove all children from the axes.

start()

Activate the tool.

stop()

Deactivate adding new children, but resizing and moving existing children is still possible.

clear()[source]#

Remove all children from the axes.

click(x, y=None, *, button=1, modifiers=None)[source]#

Simulate a click on the figure.

Parameters:
  • x (float | tuple[float, float]) – If only a float is given: the x coordinate for the click event. If a tuple of length 2 is given, it contains both the x and y coordinates for the event.

  • y (Optional[float], default: None) – The y coordinate for the event. Can be None if x is a tuple of length 2.

  • button (int, default: 1) – 1 is for left-click, 2 is for middle-click, 3 is for right-click.

  • modifiers (Optional[list[str]], default: None) – A list of modifier keys that were pressed during the click.

freeze()[source]#

Deactivate the tool but keep the children. No new children can be added and existing children cannot be moved or resized.

remove(child)[source]#

Remove an artist from the figure.

Parameters:

child

The item to be removed. Can be supplied as:

  • an integer, in which case the artist with the corresponding position in

    the list of children will be removed

  • an artist (using tool.children will give a list of all artists the tool

    is responsible for)

  • a string, which should be the id (uuid) of the artist to be removed

shutdown()[source]#

Deactivate the tool and remove all children from the axes.

start()[source]#

Activate the tool.

stop()[source]#

Deactivate adding new children, but resizing and moving existing children is still possible.