我創建使用matplotlib,因爲這3D繪圖:matplotlib和PyQt的繪製表面
fig = pylab.figure()
ax = Axes3D(fig)
surf = ax.plot_surface(X, Y, Z, cmap=cm.gray_r, linewidth=0, antialiased=True)
fig.canvas.set_window_title("Distance")
pylab.show()
這太棒了:我看到灰色-Cale的表面,我可以與它進行交互(轉面,將積,...)
現在我需要把這個圖表放在PyQt表格中。我創建從QMainWindow的繼承類這樣做:
class ViewerForm(QMainWindow):
def __init__(self, p_parent=None, p_data=None):
QMainWindow.__init__(self, parent=p_parent)
self.main_frame = QWidget()
self.figure = pyplot.figure()
self.axis = Axes3D(self.figure)
self.canvas = FigureCanvas(self.figure)
self.canvas.setParent(self.main_frame)
self.mpl_toolbar = NavigationToolbar(self.canvas, self.main_frame)
self.X, self.Y = np.meshgrid(p_data[ "axis_x" ], p_data[ "axis_y" ])
self.Z = p_data[ "values_z" ]
self.surface = self.axis.plot_surface(self.X, self.Y, self.Z, cmap=cm.gray, linewidth=0, antialiased=True)
vbox = QVBoxLayout()
vbox.addWidget(self.canvas)
vbox.addWidget(self.mpl_toolbar)
self.main_frame.setLayout(vbox)
self.setCentralWidget(self.main_frame)
當我表明這種形式,我可以看到在灰度表面作爲第一條曲線,但我不能與此交互:我不能移動用鼠標點擊表面。任何人都可以說我做錯了什麼或者我誤解了什麼?