Advertisement
Guest User

Mpl3dCanvas

a guest
Jan 31st, 2012
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. from PyQt4.QtCore import QSize
  2. from PyQt4.QtGui import QSizePolicy, QWidget, QHBoxLayout
  3.  
  4. from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
  5. from matplotlib.figure import Figure
  6. import mpl_toolkits.mplot3d.axes3d as plt3
  7.  
  8. class Mpl3dCanvas(FigureCanvas):
  9.     def __init__(self, parent=None, width = 10, height = 12, dpi = 60):
  10.         self.fig = Figure(figsize = (width, height), dpi=dpi)
  11.        
  12.         FigureCanvas.__init__(self, self.fig)
  13.         FigureCanvas.setSizePolicy(self,
  14.                 QSizePolicy.Expanding,
  15.                 QSizePolicy.Expanding)
  16.         FigureCanvas.updateGeometry(self)
  17.        
  18.         self.ax = plt3.Axes3D(self.fig)
  19.         self.ax.hold(True)
  20.  
  21.     def sizeHint(self):
  22.         w, h = self.get_width_height()
  23.         return QSize(w, h)
  24.  
  25.     def minimumSizeHint(self):
  26.         return QSize(100, 100)
  27.  
  28. class Mpl3dWidget(QWidget):
  29.     def __init__(self, parent = None):
  30.         QWidget.__init__(self, parent)
  31.         self.canvas = Mpl3dCanvas()
  32.         #self.toolbar = MyNavigationToolbar(self.canvas, self.canvas, direction = 'v')
  33.         self.hbox = QHBoxLayout()
  34.         #self.hbox.addWidget(self.toolbar)
  35.         self.hbox.addWidget(self.canvas)
  36.         self.setLayout(self.hbox)
  37.         self.axes = self.canvas.ax
  38.            
  39.     def paintEvent(self, event):
  40.         self.canvas.draw()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement