matplotlib.backend_managers
-
class matplotlib.backend_managers.ToolEvent(name, sender, tool, data=None)
[source] -
Bases:
object
Event for tool manipulation (add/remove).
-
class matplotlib.backend_managers.ToolManager(figure=None)
[source] -
Bases:
object
Manager for actions triggered by user interactions (key press, toolbar clicks, ...) on a Figure.
Attributes: -
property active_toggle
-
Currently toggled tools.
-
add_tool(self, name, tool, *args, **kwargs)
[source] -
Add tool to
ToolManager
.If successful, adds a new event
tool_trigger_{name}
where{name}
is the name of the tool; the event is fired every time the tool is triggered.Parameters: -
namestr
-
Name of the tool, treated as the ID, has to be unique.
-
toolclass_like, i.e. str or type
-
Reference to find the class of the Tool to added.
See also
-
matplotlib.backend_tools.ToolBase
- The base class for tools.
Notes
args and kwargs get passed directly to the tools constructor.
-
-
property canvas
-
Canvas managed by FigureManager.
-
property figure
-
Figure that holds the canvas.
-
get_tool(self, name, warn=True)
[source] -
Return the tool object with the given name.
For convenience, this passes tool objects through.
Parameters: -
namestr or ToolBase
-
Name of the tool, or the tool itself.
-
warnbool, default: True
-
Whether a warning should be emitted it no tool with the given name exists.
Returns: -
ToolBase or None
-
The tool or None if no tool with the given name exists.
-
-
get_tool_keymap(self, name)
[source] -
Return the keymap associated with the specified tool.
Parameters: -
namestr
-
Name of the Tool.
Returns: - list of str
-
List of keys associated with the tool.
-
-
message_event(self, message, sender=None)
[source] -
Emit a
ToolManagerMessageEvent
.
-
remove_tool(self, name)
[source] -
Remove tool named name.
Parameters: -
namestr
-
Name of the tool.
-
-
set_figure(self, figure, update_tools=True)
[source] -
Bind the given figure to the tools.
Parameters: -
figureFigure
-
update_toolsbool, default: True
-
Force tools to update figure.
-
-
toolmanager_connect(self, s, func)
[source] -
Connect event with string s to func.
Parameters: -
sstr
-
The name of the event. The following events are recognized:
- 'tool_message_event'
- 'tool_removed_event'
- 'tool_added_event'
For every tool added a new event is created
- 'tool_trigger_TOOLNAME', where TOOLNAME is the id of the tool.
-
funccallable
-
Callback function for the toolmanager event with signature:
def func(event: ToolEvent) -> Any
Returns: - cid
-
The callback id for the connection. This can be used in
toolmanager_disconnect
.
-
-
toolmanager_disconnect(self, cid)
[source] -
Disconnect callback id cid.
Example usage:
cid = toolmanager.toolmanager_connect('tool_trigger_zoom', onpress) #...later toolmanager.toolmanager_disconnect(cid)
-
property tools
-
A dict mapping tool name -> controlled tool.
-
trigger_tool(self, name, sender=None, canvasevent=None, data=None)
[source] -
Trigger a tool and emit the
tool_trigger_{name}
event.Parameters: -
namestr
-
Name of the tool.
-
senderobject
-
Object that wishes to trigger the tool.
-
canvaseventEvent
-
Original Canvas event or None.
-
dataobject
-
Extra data to pass to the tool when triggering.
-
-
update_keymap(self, name, key, *args)
[source] -
Set the keymap to associate with the specified tool.
Parameters: -
namestr
-
Name of the Tool.
-
keysstr or list of str
-
Keys to associate with the tool.
-
-
-
class matplotlib.backend_managers.ToolManagerMessageEvent(name, sender, message)
[source] -
Bases:
object
Event carrying messages from toolmanager.
Messages usually get displayed to the user by the toolbar.
-
class matplotlib.backend_managers.ToolTriggerEvent(name, sender, tool, canvasevent=None, data=None)
[source] -
Bases:
matplotlib.backend_managers.ToolEvent
Event to inform that a tool has been triggered.
© 2012–2018 Matplotlib Development Team. All rights reserved.
Licensed under the Matplotlib License Agreement.
https://matplotlib.org/3.3.3/api/backend_managers_api.html