-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
MEP22: Navigation by events #3652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
8cceed4
3118a5a
b4d5fcf
1e8af47
622cb95
d1a9de4
3f89d52
4f3c10b
6065daa
f6a2f19
05db3b6
c08fe56
b207a72
9266447
a53419a
704c717
5056729
e6a4e1e
8942c47
022de6f
2c9a195
cafe668
224f745
94c711e
67257e7
ffa65d6
6739ee0
d18206f
34a52c8
c2da483
44a9b0e
a2ed47f
0665890
411e6e2
d484ebd
75bf97b
6cc040b
0ff5997
af6734f
78513d2
377ff54
7dbbf58
dd66b57
67a414f
e415d8d
1213086
ba61dec
9f2ee2b
9da2b13
110253f
e2804ea
9a64b7e
64f947f
e8cd5d5
4bbcf4e
73a2661
1b83628
e4edd23
d4ac2fb
a7640ef
48a6971
8dafe09
a0695d0
328b169
aac4744
f09b9ef
def3a52
9ee7e25
5eae4e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
'''This example demonstrates how the `matplotlib.backend_bases.NavigationBase` | ||
class allows to: | ||
* Modify the Toolbar | ||
* Add tools | ||
* Remove tools | ||
''' | ||
|
||
|
||
from __future__ import print_function | ||
import matplotlib | ||
matplotlib.use('GTK3Cairo') | ||
# matplotlib.use('TkAGG') | ||
matplotlib.rcParams['toolbar'] = 'navigation' | ||
import matplotlib.pyplot as plt | ||
from matplotlib.backend_tools import ToolBase | ||
|
||
|
||
# Create a simple tool to list all the tools | ||
class ListTools(ToolBase): | ||
'''List all the tools controlled by `Navigation`''' | ||
# keyboard shortcut | ||
keymap = 'm' | ||
description = 'List Tools' | ||
|
@@ -34,9 +42,9 @@ def trigger(self, *args, **kwargs): | |
print("{0:12} {1:45}").format(group, active) | ||
|
||
|
||
# A simple example of copy canvas | ||
# ref: at https://github.com/matplotlib/matplotlib/issues/1987 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, should be a class docstring |
||
class CopyToolGTK3(ToolBase): | ||
'''Copy canvas to clipboard''' | ||
keymap = 'ctrl+c' | ||
description = 'Copy canvas' | ||
|
||
|
@@ -54,10 +62,16 @@ def trigger(self, *args, **kwargs): | |
|
||
# Add the custom tools that we created | ||
fig.canvas.manager.navigation.add_tool('List', ListTools) | ||
if matplotlib.rcParams['backend'] == 'GTK3Cairo': | ||
fig.canvas.manager.navigation.add_tool('copy', CopyToolGTK3) | ||
fig.canvas.manager.navigation.add_tool('copy', CopyToolGTK3) | ||
|
||
# Add an existing tool to new group `foo`. | ||
# It can be added as many times as we want | ||
fig.canvas.manager.toolbar.add_tool('zoom', 'foo') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simple answer it ain't we have here |
||
# Uncomment to remove the forward button | ||
# fig.canvas.manager.navigation.remove_tool('forward') | ||
|
||
# Remove the forward button | ||
fig.canvas.manager.navigation.remove_tool('forward') | ||
|
||
# To add a custom tool to the toolbar at specific location | ||
fig.canvas.manager.toolbar.add_tool('List', 'navigation', 1) | ||
|
||
plt.show() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these are examples, I would suggest getting rid of extraneous commented out code, and also highlight important lines of code such as this one. For example, is it important that it gets called before importing pyplot? What is it for? Perhaps a short docstring at the top of this example would help explain its purpose/goal that it is demonstrating?