Differences between revisions 1 and 2

Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
This is a very basic example showing how to display a matplotlib plot within a Qt application using PySide This is a very basic example showing how to display a matplotlib plot within a Qt application using PySide.
In case of problems try to change the rcParam entry “backend.qt4” to "PySide" (e.g. by in the matplotlibrc file).

This is a very basic example showing how to display a matplotlib plot within a Qt application using PySide. In case of problems try to change the rcParam entry “backend.qt4” to "PySide" (e.g. by in the matplotlibrc file).

   1 #!/usr/bin/env python
   2 import sys
   3 import matplotlib
   4 matplotlib.use('Qt4Agg')
   5 import pylab
   6 
   7 from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
   8 from matplotlib.figure import Figure
   9 
  10 from PySide import QtCore, QtGui
  11 
  12 if __name__ == '__main__':
  13     app = QtGui.QApplication(sys.argv)
  14 
  15     # generate the plot
  16     fig = Figure(figsize=(600,600), dpi=72, facecolor=(1,1,1), edgecolor=(0,0,0))
  17     ax = fig.add_subplot(111)
  18     ax.plot([0,1])
  19     # generate the canvas to display the plot
  20     canvas = FigureCanvas(fig)
  21 
  22     win = QtGui.QMainWindow()
  23     # add the plot canvas to a window
  24     win.setCentralWidget(canvas)
  25 
  26     win.show()
  27 
  28     sys.exit(app.exec_())

Cookbook/Matplotlib/PySide (last edited 2012-06-10 13:25:07 by gmg)