Matplotlib:pyside

日期2012-06-10(最后修改),2011-07-06(创建)

这是一个非常基本的示例,展示了如何使用 PySide 在 Qt 应用程序中显示 matplotlib 绘图。如果遇到问题,请尝试将 rcParam 条目“backend.qt4”更改为“PySide”(例如,在 matplotlibrc 文件中)。

在 [ ]
#!/usr/bin/env python
import sys
import matplotlib
matplotlib.use('Qt4Agg')
import pylab

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure

from PySide import QtCore, QtGui

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)

    # generate the plot
    fig = Figure(figsize=(600,600), dpi=72, facecolor=(1,1,1), edgecolor=(0,0,0))
    ax = fig.add_subplot(111)
    ax.plot([0,1])
    # generate the canvas to display the plot
    canvas = FigureCanvas(fig)

    win = QtGui.QMainWindow()
    # add the plot canvas to a window
    win.setCentralWidget(canvas)

    win.show()

    sys.exit(app.exec_())

章节作者:Unknown[82],Unknown[111]