Im folgenden Code sollten Sie finden, was Sie suchen (zumindest mit matplotlib 1.0.1 und pyqt 4.8):
class MplPlot3dCanvas(FigureCanvas):
def __init__(self):
self.surfs = [] # [{"xx":,"yy:","val:"}]
self.fig = Figure()
self.fig.suptitle("this is the figure title", fontsize=12)
FigureCanvas.__init__(self, self.fig)
FigureCanvas.setSizePolicy(self,
QSizePolicy.Expanding,
QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
self.ax = Axes3D(self.fig) # Canvas figure must be created for mouse rotation
self.ax.set_xlabel('row (m CCD)')
self.ax.set_ylabel('col (m CCD)')
self.ax.set_zlabel('Phi (m)')
self.format_coord_org = self.ax.format_coord
self.ax.format_coord = self.report_pixel
def report_pixel(self, xd, yd):
s = self.format_coord_org(xd, yd)
s = s.replace(",", " ")
return s
def update_view(self):
for plt in self.plots:
# del plt
self.ax.collections.remove(plt)
self.plots = []
for surf in self.surfs:
plt = self.ax.plot_surface(surf["xx"], surf["yy"], surf["val"], rstride=5, cstride=5, cmap=cm.jet, linewidth=1, antialiased=True)
self.plots.append(plt)
self.draw()
class MplPlot3dView(QWidget):
def __init__(self, parent = None):
super(MplPlot3dView, self).__init__(parent)
self.canvas = MplPlot3dCanvas()
self.toolbar = NavigationToolbar(self.canvas, self.canvas)
self.vbox = QVBoxLayout()
self.vbox.addWidget(self.canvas)
self.vbox.addWidget(self.toolbar)
self.setLayout(self.vbox)
self.to_update = False
Dann müssen Sie nur noch hinzufügen ein QWidget zu deinem QtaWidget und befördere es auf die neue Klasse MplPlot3dView (du findest leicht eine Ressource im Netz darüber, wie man das macht).