9
9
import sys
10
10
11
11
import numpy as np
12
+
12
13
import matplotlib
13
14
matplotlib .use ("Qt4Agg" )
14
- from matplotlib .figure import Figure
15
15
from matplotlib .backend_bases import key_press_handler
16
16
from matplotlib .backends .backend_qt4agg import (
17
17
FigureCanvasQTAgg as FigureCanvas ,
18
18
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
28
21
29
22
30
- class AppForm (QMainWindow ):
23
+ class AppForm (QtGui . QMainWindow ):
31
24
def __init__ (self , parent = None ):
32
- QMainWindow .__init__ (self , parent )
33
- #self.x, self.y = self.get_data()
25
+ QtGui .QMainWindow .__init__ (self , parent )
34
26
self .data = self .get_data2 ()
35
27
self .create_main_frame ()
36
28
self .on_draw ()
37
29
38
30
def create_main_frame (self ):
39
- self .main_frame = QWidget ()
31
+ self .main_frame = QtGui . QWidget ()
40
32
41
33
self .fig = Figure ((5.0 , 4.0 ), dpi = 100 )
42
34
self .canvas = FigureCanvas (self .fig )
43
35
self .canvas .setParent (self .main_frame )
44
- self .canvas .setFocusPolicy (Qt .StrongFocus )
36
+ self .canvas .setFocusPolicy (QtCore . Qt .StrongFocus )
45
37
self .canvas .setFocus ()
46
38
47
39
self .mpl_toolbar = NavigationToolbar (self .canvas , self .main_frame )
48
40
49
41
self .canvas .mpl_connect ('key_press_event' , self .on_key_press )
50
42
51
- vbox = QVBoxLayout ()
43
+ vbox = QtGui . QVBoxLayout ()
52
44
vbox .addWidget (self .canvas ) # the matplotlib canvas
53
45
vbox .addWidget (self .mpl_toolbar )
54
46
self .main_frame .setLayout (vbox )
@@ -60,9 +52,7 @@ def get_data2(self):
60
52
def on_draw (self ):
61
53
self .fig .clear ()
62
54
self .axes = self .fig .add_subplot (111 )
63
- #self.axes.plot(self.x, self.y, 'ro')
64
55
self .axes .imshow (self .data , interpolation = 'nearest' )
65
- #self.axes.plot([1,2,3])
66
56
self .canvas .draw ()
67
57
68
58
def on_key_press (self , event ):
@@ -73,7 +63,7 @@ def on_key_press(self, event):
73
63
74
64
75
65
def main ():
76
- app = QApplication (sys .argv )
66
+ app = QtGui . QApplication (sys .argv )
77
67
form = AppForm ()
78
68
form .show ()
79
69
app .exec_ ()
0 commit comments