1
1
import matplotlib
2
- # matplotlib.use('GTK3Cairo')
3
- matplotlib .use ('TkAGG' )
2
+ matplotlib .use ('GTK3Cairo' )
3
+ # matplotlib.use('TkAGG')
4
4
matplotlib .rcParams ['toolbar' ] = 'navigation'
5
5
import matplotlib .pyplot as plt
6
6
from matplotlib .backend_tools import ToolBase
7
7
8
8
9
- #Create a simple tool to list all the tools
9
+ # Create a simple tool to list all the tools
10
10
class ListTools (ToolBase ):
11
- #keyboard shortcut
11
+ # keyboard shortcut
12
12
keymap = 'm'
13
- #Name used as id, must be unique between tools of the same navigation
13
+ # Name used as id, must be unique between tools of the same navigation
14
14
name = 'List'
15
15
description = 'List Tools'
16
- #Where to put it in the toolbar, -1 = at the end, None = Not in toolbar
16
+ # Where to put it in the toolbar, -1 = at the end, None = Not in toolbar
17
17
position = - 1
18
18
19
19
def trigger (self , event ):
20
- #The most important attributes are navigation and figure
20
+ # The most important attributes are navigation and figure
21
21
self .navigation .list_tools ()
22
22
23
23
24
- #A simple example of copy canvas
25
- #ref: at https://github.com/matplotlib/matplotlib/issues/1987
26
- class CopyTool (ToolBase ):
24
+ # A simple example of copy canvas
25
+ # ref: at https://github.com/matplotlib/matplotlib/issues/1987
26
+ class CopyToolGTK3 (ToolBase ):
27
27
keymap = 'ctrl+c'
28
28
name = 'Copy'
29
29
description = 'Copy canvas'
30
- position = - 1
30
+ # It is not added to the toolbar as a button
31
+ position = None
31
32
32
33
def trigger (self , event ):
33
34
from gi .repository import Gtk , Gdk
@@ -41,13 +42,12 @@ def trigger(self, event):
41
42
fig = plt .figure ()
42
43
plt .plot ([1 , 2 , 3 ])
43
44
44
- #If we are in the old toolbar, don't try to modify it
45
- if matplotlib .rcParams ['toolbar' ] in ('navigation' , 'None' ):
46
- ##Add the custom tools that we created
47
- fig .canvas .manager .navigation .add_tool (ListTools )
48
- fig .canvas .manager .navigation .add_tool (CopyTool )
45
+ # Add the custom tools that we created
46
+ fig .canvas .manager .navigation .add_tool (ListTools )
47
+ if matplotlib .rcParams ['backend' ] == 'GTK3Cairo' :
48
+ fig .canvas .manager .navigation .add_tool (CopyToolGTK3 )
49
49
50
- ## Just for fun, lets remove the back button
51
- fig .canvas .manager .navigation .remove_tool ('Back' )
50
+ # Just for fun, lets remove the back button
51
+ fig .canvas .manager .navigation .remove_tool ('Back' )
52
52
53
53
plt .show ()
0 commit comments