123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- ####################################################
- # Adopted from pyqtgraph (MIT license)
- #from pyqtgraph.Qt import QtGui, QtCore, USE_PYSIDE
- USE_PYSIDE = True
-
- import matplotlib
- matplotlib.use('Qt4Agg')
- #matplotlib.rcParams['backend.qt4']='PySide'
-
- if USE_PYSIDE == True:
- matplotlib.rcParams['backend.qt4']='PySide'
- from PySide import QtCore, QtGui
- else:
- from PyQt4 import QtCore, QtGui
-
-
- from matplotlib import rc #
- #matplotlib.rcParams['text.latex.preamble']=[r"\usepackage{timet,amsmath,amssymb}"] #
- #rc('font',**{'family':'serif','serif':['timet']})
- rc('font',**{'size':8}) #
- #rc('text', usetex=True)
-
- from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
- from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
- from matplotlib.figure import Figure
-
- class MatplotlibWidget(QtGui.QWidget):
- """
- Implements a Matplotlib figure inside a QWidget.
- Use getFigure() and redraw() to interact with matplotlib.
-
- Example::
-
- mw = MatplotlibWidget()
- subplot = mw.getFigure().add_subplot(111)
- subplot.plot(x,y)
- mw.draw()
- """
-
- def __init__(self, parent=None, size=(5.0, 4.0), dpi=100):
- # thingy is the designer designated parent, layout manager, etc.
- self.size = size
- self.dpi = dpi
-
- #QtGui.QWidget.__init__(self, thingy)
- #super(thingy, self).__init__( MatplotlibWidget )
- #super(MatplotlibWidget, self).__init__( self, parent )
- super(MatplotlibWidget, self).__init__(parent)
-
- self.fig = Figure(size, dpi=dpi)
- self.canvas = FigureCanvas(self.fig)
- self.canvas.setParent(self)
- self.toolbar = NavigationToolbar(self.canvas, self)
-
- self.vbox = QtGui.QVBoxLayout()
- self.vbox.addWidget(self.toolbar)
- self.vbox.addWidget(self.canvas)
-
- self.setLayout(self.vbox)
-
- def Clear(self):
-
- for ax in self.fig.axes:
- ax.cla()
- #ax.draw()
- self.fig.delaxes(ax)
-
- self.canvas.draw()
-
- #print ("axes", self.fig.axes)
-
- # del self.fig
- # del self.canvas
- # del self.toolbar
- # del self.vbox
- #
- # self.fig = Figure((3,4), dpi=self.dpi)
- # self.canvas = FigureCanvas(self.fig)
- # self.canvas.setParent(self)
- # self.toolbar = NavigationToolbar(self.canvas, self)
- #
- # self.vbox = QtGui.QVBoxLayout()
- # self.vbox.addWidget(self.toolbar)
- # self.vbox.addWidget(self.canvas)
-
- #self.setLayout(self.vbox)
-
-
- def getFigure(self):
- return self.fig
-
- def draw(self):
- self.canvas.draw()
|