Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Mpl3dCanvas

By: a guest on Jan 31st, 2012  |  syntax: Python  |  size: 1.36 KB  |  views: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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()