Borehole NMR processing
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

MatplotlibWidget.py 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. ####################################################
  2. # Adopted from pyqtgraph (MIT license)
  3. #from pyqtgraph.Qt import QtGui, QtCore, USE_PYSIDE
  4. USE_PYSIDE = True
  5. import matplotlib
  6. matplotlib.use('Qt4Agg')
  7. #matplotlib.rcParams['backend.qt4']='PySide'
  8. if USE_PYSIDE == True:
  9. matplotlib.rcParams['backend.qt4']='PySide'
  10. from PySide import QtCore, QtGui
  11. else:
  12. from PyQt4 import QtCore, QtGui
  13. from matplotlib import rc #
  14. #matplotlib.rcParams['text.latex.preamble']=[r"\usepackage{timet,amsmath,amssymb}"] #
  15. #rc('font',**{'family':'serif','serif':['timet']})
  16. rc('font',**{'size':8}) #
  17. #rc('text', usetex=True)
  18. from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
  19. from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
  20. from matplotlib.figure import Figure
  21. class MatplotlibWidget(QtGui.QWidget):
  22. """
  23. Implements a Matplotlib figure inside a QWidget.
  24. Use getFigure() and redraw() to interact with matplotlib.
  25. Example::
  26. mw = MatplotlibWidget()
  27. subplot = mw.getFigure().add_subplot(111)
  28. subplot.plot(x,y)
  29. mw.draw()
  30. """
  31. def __init__(self, parent=None, size=(5.0, 4.0), dpi=100):
  32. # thingy is the designer designated parent, layout manager, etc.
  33. self.size = size
  34. self.dpi = dpi
  35. #QtGui.QWidget.__init__(self, thingy)
  36. #super(thingy, self).__init__( MatplotlibWidget )
  37. #super(MatplotlibWidget, self).__init__( self, parent )
  38. super(MatplotlibWidget, self).__init__(parent)
  39. self.fig = Figure(size, dpi=dpi)
  40. self.canvas = FigureCanvas(self.fig)
  41. self.canvas.setParent(self)
  42. self.toolbar = NavigationToolbar(self.canvas, self)
  43. self.vbox = QtGui.QVBoxLayout()
  44. self.vbox.addWidget(self.toolbar)
  45. self.vbox.addWidget(self.canvas)
  46. self.setLayout(self.vbox)
  47. def Clear(self):
  48. for ax in self.fig.axes:
  49. ax.cla()
  50. #ax.draw()
  51. self.fig.delaxes(ax)
  52. self.canvas.draw()
  53. #print ("axes", self.fig.axes)
  54. # del self.fig
  55. # del self.canvas
  56. # del self.toolbar
  57. # del self.vbox
  58. #
  59. # self.fig = Figure((3,4), dpi=self.dpi)
  60. # self.canvas = FigureCanvas(self.fig)
  61. # self.canvas.setParent(self)
  62. # self.toolbar = NavigationToolbar(self.canvas, self)
  63. #
  64. # self.vbox = QtGui.QVBoxLayout()
  65. # self.vbox.addWidget(self.toolbar)
  66. # self.vbox.addWidget(self.canvas)
  67. #self.setLayout(self.vbox)
  68. def getFigure(self):
  69. return self.fig
  70. def draw(self):
  71. self.canvas.draw()