matplotlib.backend_managers#

classmatplotlib.backend_managers.ToolEvent(name,sender,tool,data=None)[source]#

Bases:object

Event for tool manipulation (add/remove).

classmatplotlib.backend_managers.ToolManager(figure=None)[source]#

Bases:object

Manager for actions triggered by user interactions (key press, toolbarclicks, ...) on a Figure.

Attributes:
figureFigure

Figure that holds the canvas.

keypresslockLockDraw

LockDraw object to know if thecanvas key_press_event is locked.

messagelockLockDraw

LockDraw object to know if the message is available to write.

propertyactive_toggle#

Currently toggled tools.

add_tool(name,tool,*args,**kwargs)[source]#

Addtool toToolManager.

If successful, adds a new eventtool_trigger_{name} where{name} is thename of the tool; the event is fired every time thetool is triggered.

Parameters:
namestr

Name of the tool, treated as the ID, has to be unique.

tooltype

Class of the tool to be added. A subclass will be usedinstead if one was registered for the current canvas class.

*args, **kwargs

Passed to thetool's constructor.

See also

matplotlib.backend_tools.ToolBase

The base class for tools.

propertycanvas#

Canvas managed by FigureManager.

propertyfigure#

Figure that holds the canvas.

get_tool(name,warn=True)[source]#

Return the tool object with the given name.

For convenience, this passes tool objects through.

Parameters:
namestr orToolBase

Name of the tool, or the tool itself.

warnbool, default: True

Whether a warning should be emitted it no tool with the given nameexists.

Returns:
ToolBase or None

The tool or None if no tool with the given name exists.

get_tool_keymap(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(message,sender=None)[source]#

Emit aToolManagerMessageEvent.

remove_tool(name)[source]#

Remove tool namedname.

Parameters:
namestr

Name of the tool.

set_figure(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(s,func)[source]#

Connect event with strings tofunc.

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:

deffunc(event:ToolEvent)->Any
Returns:
cid

The callback id for the connection. This can be used intoolmanager_disconnect.

toolmanager_disconnect(cid)[source]#

Disconnect callback idcid.

Example usage:

cid=toolmanager.toolmanager_connect('tool_trigger_zoom',onpress)#...latertoolmanager.toolmanager_disconnect(cid)
propertytools#

A dict mapping tool name -> controlled tool.

trigger_tool(name,sender=None,canvasevent=None,data=None)[source]#

Trigger a tool and emit thetool_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(name,key)[source]#

Set the keymap to associate with the specified tool.

Parameters:
namestr

Name of the Tool.

keystr or list of str

Keys to associate with the tool.

classmatplotlib.backend_managers.ToolManagerMessageEvent(name,sender,message)[source]#

Bases:object

Event carrying messages from toolmanager.

Messages usually get displayed to the user by the toolbar.

classmatplotlib.backend_managers.ToolTriggerEvent(name,sender,tool,canvasevent=None,data=None)[source]#

Bases:ToolEvent

Event to inform that a tool has been triggered.