8000 whats new · CodyCasteneda/matplotlib@a0695d0 · GitHub
[go: up one dir, main page]

Skip to content

Commit a0695d0

Browse files
committed
whats new
1 parent 8dafe09 commit a0695d0

File tree

4 files changed

+80
-3
lines changed

4 files changed

+80
-3
lines changed

doc/users/whats_new/rcparams.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,17 @@ Added "figure.titlesize" and "figure.titleweight" keys to rcParams
1515
Two new keys were added to rcParams to control the default font size and weight
1616
used by the figure title (as emitted by ``pyplot.suptitle()``).
1717

18+
1819
``image.composite_image`` added to rcParams
1920
```````````````````````````````````````````
2021
Controls whether vector graphics backends (i.e. PDF, PS, and SVG) combine
2122
multiple images on a set of axes into a single composite image. Saving each
2223
image individually can be useful if you generate vector graphics files in
2324
matplotlib and then edit the files further in Inkscape or other programs.
25+
26+
27+
Added "toolmanager" to "toolbar" possible values
28+
````````````````````````````````````````````````
29+
30+
The new value enables the use of ``ToolManager``
31+

doc/users/whats_new/toolmanager.rst

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
ToolManager
2+
-----------
3+
4+
Federico Ariza wrote the new `matplotlib.backend_managers.ToolManager` that comes as replacement for `NavigationToolbar2`
5+
6+
`ToolManager` offers a new way of looking at the user interactions with the figures.
7+
Before we had the `NavigationToolbar2` with its own tools like `zoom/pan/home/save/...` and also we had the shortcuts like
8+
`yscale/grid/quit/....`
9+
`Toolmanager` relocate all those actions as `Tools` (located in `matplotlib.backend_tools`), and defines a way to `access/trigger/reconfigure` them.
10+
11+
The `Toolbars` are replaced for `ToolContainers` that are just GUI interfaces to `trigger` the tools. But don't worry the default backends include a `ToolContainer` called `toolbar`
12+
13+
14+
.. note::
15+
For the moment the `ToolManager` is working only with `GTK3` and `Tk` backends.
16+
Make sure you are using one of those.
17+
Port for the rest of the backends is comming soon.
18+
19+
To activate the `ToolManager` include the following at the top of your file:
20+
21+
>>> matplotlib.rcParams['toolbar'] = 'toolmanager'
22+
23+
24+
Interact with the ToolContainer
25+
```````````````````````````````
26+
27+
The most important feature is the ability to easily reconfigure the ToolContainer (aka toolbar).
28+
For example, if we want to remove the "forward" button we would just do.
29+
30+
>>> fig.canvas.manager.toolmanager.remove_tool('forward')
31+
32+
Now if you want to programmatically trigger the "home" button
33+
34+
>>> fig.canvas.manager.toolmanager.trigger_tool('home')
35+
36+
37+
New Tools
38+
`````````
39+
40+
It is possible to add new tools to the ToolManager
41+
42+
A very simple tool that prints "You're awesome" would be::
43+
44+
from matplotlib.backend_tools import ToolBase
45+
class AwesomeTool(ToolBase):
46+
def trigger(self, *args, **kwargs):
47+
print("You're awesome")
48+
49+
50+
To add this tool to `ToolManager`
51+
52+
>>> fig.canvas.manager.toolmanager.add_tool('Awesome', AwesomeTool)
53+
54+
If we want to add a shortcut ("d") for the tool
55+
56+
>>> fig.canvas.manager.toolmanager.update_keymap('Awesome', 'd')
57+
58+
59+
To add it to the toolbar inside the group 'foo'
60+
61+
>>> fig.canvas.manager.toolbar.add_tool('Awesome', 'foo')
62+
63+
64+
There is a second class of tools, "Toggleable Tools", this are almost the same as our basic tools, just that belong to a group, and are mutually exclusive inside that group.
65+
For tools derived from `ToolToggleBase` there are two basic methods `enable` and `disable` that are called automatically whenever it is toggled.
66+
67+
68+
A full example is located in :ref:`user_interfaces-toolmanager`

examples/user_interfaces/toolmanager.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
'''This example demonstrates how the `matplotlib.backend_bases.NavigationBase`
2-
class allows to:
1+
'''This example demonstrates how to:
32
* Modify the Toolbar
3+
* Create tools
44
* Add tools
55
* Remove tools
6+
Using `matplotlib.backend_managers.ToolManager`
67
'''
78

89

lib/matplotlib/backend_bases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3227,7 +3227,7 @@ class ToolContainerBase(object):
32273227
"""
32283228
Base class for all tool containers, e.g. toolbars.
32293229
3230-
Attributes
3230+
Attributes
32313231
----------
32323232
toolmanager : `ToolManager` object that holds the tools that
32333233
this `ToolContainer` wants to communicate with.

0 commit comments

Comments
 (0)
0