99import sys
1010
1111import numpy as np
12+
1213import matplotlib
1314matplotlib .use ("Qt4Agg" )
14- from matplotlib .figure import Figure
1515from matplotlib .backend_bases import key_press_handler
1616from matplotlib .backends .backend_qt4agg import (
1717 FigureCanvasQTAgg as FigureCanvas ,
1818 NavigationToolbar2QT as NavigationToolbar )
19- from matplotlib .backends import qt_compat
20- use_pyside = qt_compat .QT_API == qt_compat .QT_API_PYSIDE
21-
22- if use_pyside :
23- from PySide .QtCore import *
24- from PySide .QtGui import *
25- else :
26- from PyQt4 .QtCore import *
27- from PyQt4 .QtGui import *
19+ from matplotlib .backends .qt_compat import QtCore , QtGui
20+ from matplotlib .figure import Figure
2821
2922
30- class AppForm (QMainWindow ):
23+ class AppForm (QtGui . QMainWindow ):
3124 def __init__ (self , parent = None ):
32- QMainWindow .__init__ (self , parent )
33- #self.x, self.y = self.get_data()
25+ QtGui .QMainWindow .__init__ (self , parent )
3426 self .data = self .get_data2 ()
3527 self .create_main_frame ()
3628 self .on_draw ()
3729
3830 def create_main_frame (self ):
39- self .main_frame = QWidget ()
31+ self .main_frame = QtGui . QWidget ()
4032
4133 self .fig = Figure ((5.0 , 4.0 ), dpi = 100 )
4234 self .canvas = FigureCanvas (self .fig )
4335 self .canvas .setParent (self .main_frame )
44- self .canvas .setFocusPolicy (Qt .StrongFocus )
36+ self .canvas .setFocusPolicy (QtCore . Qt .StrongFocus )
4537 self .canvas .setFocus ()
4638
4739 self .mpl_toolbar = NavigationToolbar (self .canvas , self .main_frame )
4840
4941 self .canvas .mpl_connect ('key_press_event' , self .on_key_press )
5042
51- vbox = QVBoxLayout ()
43+ vbox = QtGui . QVBoxLayout ()
5244 vbox .addWidget (self .canvas ) # the matplotlib canvas
5345 vbox .addWidget (self .mpl_toolbar )
5446 self .main_frame .setLayout (vbox )
@@ -60,9 +52,7 @@ def get_data2(self):
6052 def on_draw (self ):
6153 self .fig .clear ()
6254 self .axes = self .fig .add_subplot (111 )
63- #self.axes.plot(self.x, self.y, 'ro')
6455 self .axes .imshow (self .data , interpolation = 'nearest' )
65- #self.axes.plot([1,2,3])
6656 self .canvas .draw ()
6757
6858 def on_key_press (self , event ):
@@ -73,7 +63,7 @@ def on_key_press(self, event):
7363
7464
7565def main ():
76- app = QApplication (sys .argv )
66+ app = QtGui . QApplication (sys .argv )
7767 form = AppForm ()
7868 form .show ()
7969 app .exec_ ()
0 commit comments