Cookbook/Matplotlib/PySide - SciPy wiki dump

This is an archival dump of old wiki content --- see scipy.org for current material.
Please see http://scipy-cookbook.readthedocs.org/

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_())

SciPy: Cookbook/Matplotlib/PySide (last edited 2015年10月24日 17:48:23 by anonymous)

AltStyle によって変換されたページ (->オリジナル) /