1+ from __future__ import print_function
2+
13import sys
4+
25import numpy as np
36from 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 )
511from PyQt4 .QtCore import *
612from PyQt4 .QtGui import *
713
8- from matplotlib .backends .backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
9- from matplotlib .backends .backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
10-
1114
1215class AppForm (QMainWindow ):
1316 def __init__ (self , parent = None ):
@@ -23,21 +26,21 @@ def create_main_frame(self):
2326 self .fig = Figure ((5.0 , 4.0 ), dpi = 100 )
2427 self .canvas = FigureCanvas (self .fig )
2528 self .canvas .setParent (self .main_frame )
26- self .canvas .setFocusPolicy ( Qt .StrongFocus )
29+ self .canvas .setFocusPolicy (Qt .StrongFocus )
2730 self .canvas .setFocus ()
2831
2932 self .mpl_toolbar = NavigationToolbar (self .canvas , self .main_frame )
3033
3134 self .canvas .mpl_connect ('key_press_event' , self .on_key_press )
3235
3336 vbox = QVBoxLayout ()
34- vbox .addWidget (self .canvas ) # the matplotlib canvas
37+ vbox .addWidget (self .canvas ) # the matplotlib canvas
3538 vbox .addWidget (self .mpl_toolbar )
3639 self .main_frame .setLayout (vbox )
3740 self .setCentralWidget (self .main_frame )
3841
3942 def get_data2 (self ):
40- return np .arange (20 ).reshape ([4 ,5 ]).copy ()
43+ return np .arange (20 ).reshape ([4 , 5 ]).copy ()
4144
4245 def on_draw (self ):
4346 self .fig .clear ()
@@ -48,11 +51,12 @@ def on_draw(self):
4851 self .canvas .draw ()
4952
5053 def on_key_press (self , event ):
51- print 'you pressed' , event .key
54+ print ( 'you pressed' , event .key )
5255 # implement the default mpl key press events described at
5356 # http://matplotlib.sourceforge.net/users/navigation_toolbar.html#navigation-keyboard-shortcuts
5457 key_press_handler (event , self .canvas , self .mpl_toolbar )
5558
59+
5660def main ():
5761 app = QApplication (sys .argv )
5862 form = AppForm ()
0 commit comments