1
+ from __future__ import print_function
2
+
1
3
import sys
4
+
2
5
import numpy as np
3
6
from matplotlib .figure import Figure
4
- from matplotlib .backend_bases import FigureManagerBase , key_press_handler
7
+ from matplotlib .backend_bases import key_press_handler
8
+ from matplotlib .backends .backend_qt4agg import (
9
+ FigureCanvasQTAgg as FigureCanvas ,
10
+ NavigationToolbar2QTAgg as NavigationToolbar )
5
11
from PyQt4 .QtCore import *
6
12
from PyQt4 .QtGui import *
7
13
8
- from matplotlib .backends .backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
9
- from matplotlib .backends .backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
10
-
11
14
12
15
class AppForm (QMainWindow ):
13
16
def __init__ (self , parent = None ):
@@ -23,21 +26,21 @@ def create_main_frame(self):
23
26
self .fig = Figure ((5.0 , 4.0 ), dpi = 100 )
24
27
self .canvas = FigureCanvas (self .fig )
25
28
self .canvas .setParent (self .main_frame )
26
- self .canvas .setFocusPolicy ( Qt .StrongFocus )
29
+ self .canvas .setFocusPolicy (Qt .StrongFocus )
27
30
self .canvas .setFocus ()
28
31
29
32
self .mpl_toolbar = NavigationToolbar (self .canvas , self .main_frame )
30
33
31
34
self .canvas .mpl_connect ('key_press_event' , self .on_key_press )
32
35
33
36
vbox = QVBoxLayout ()
34
- vbox .addWidget (self .canvas ) # the matplotlib canvas
37
+ vbox .addWidget (self .canvas ) # the matplotlib canvas
35
38
vbox .addWidget (self .mpl_toolbar )
36
39
self .main_frame .setLayout (vbox )
37
40
self .setCentralWidget (self .main_frame )
38
41
39
42
def get_data2 (self ):
40
- return np .arange (20 ).reshape ([4 ,5 ]).copy ()
43
+ return np .arange (20 ).reshape ([4 , 5 ]).copy ()
41
44
42
45
def on_draw (self ):
43
46
self .fig .clear ()
@@ -48,11 +51,12 @@ def on_draw(self):
48
51
self .canvas .draw ()
49
52
50
53
def on_key_press (self , event ):
51
- print 'you pressed' , event .key
54
+ print ( 'you pressed' , event .key )
52
55
# implement the default mpl key press events described at
53
56
# http://matplotlib.sourceforge.net/users/navigation_toolbar.html#navigation-keyboard-shortcuts
54
57
key_press_handler (event , self .canvas , self .mpl_toolbar )
55
58
59
+
56
60
def main ():
57
61
app = QApplication (sys .argv )
58
62
form = AppForm ()
0 commit comments