如何将 matplotlib 功能与 QGraphicsView 集成?
How to integrate matplotlib fumction with QGraphicView?
我正在使用 Qt Designer 和 PyQt4 开发桌面应用程序。我需要显示一些带有轮廓的图形,在 python 中可以用 matplotlib.pyplot.contourf 完成。我想在 QGraphicView 对象中显示结果。
我正在尝试通过将 QGraphicView 提升为 Qt-Designer 中的 pygtgraph 来实现。如果 QGraphicView 的对象名称是 CNOPlot 我已经写
import matplotlib.pyplot as plt
self.CNOPlot.plot(plt.contourf(xx, yy, Z,cmap=plt.cm.autumn, alpha=0.8))
它在单独的 window 中给出输出。
我希望这是在 CNOPlot 中绘制的。
这是一个简短的例子:
import matplotlib.pyplot as plt
from PyQt4 import QtGui
from PyQt4.Qt import Qt
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
class MyView(QtGui.QGraphicsView):
def __init__(self):
QtGui.QGraphicsView.__init__(self)
scene = QtGui.QGraphicsScene(self)
self.scene = scene
figure = Figure()
axes = figure.gca()
axes.set_title("title")
axes.plot(plt.contourf(xx, yy, Z,cmap=plt.cm.autumn, alpha=0.8))
canvas = FigureCanvas(figure)
canvas.setGeometry(0, 0, 500, 500)
scene.addWidget(canvas)
self.setScene(scene)
我正在使用 Qt Designer 和 PyQt4 开发桌面应用程序。我需要显示一些带有轮廓的图形,在 python 中可以用 matplotlib.pyplot.contourf 完成。我想在 QGraphicView 对象中显示结果。
我正在尝试通过将 QGraphicView 提升为 Qt-Designer 中的 pygtgraph 来实现。如果 QGraphicView 的对象名称是 CNOPlot 我已经写
import matplotlib.pyplot as plt
self.CNOPlot.plot(plt.contourf(xx, yy, Z,cmap=plt.cm.autumn, alpha=0.8))
它在单独的 window 中给出输出。 我希望这是在 CNOPlot 中绘制的。
这是一个简短的例子:
import matplotlib.pyplot as plt
from PyQt4 import QtGui
from PyQt4.Qt import Qt
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
class MyView(QtGui.QGraphicsView):
def __init__(self):
QtGui.QGraphicsView.__init__(self)
scene = QtGui.QGraphicsScene(self)
self.scene = scene
figure = Figure()
axes = figure.gca()
axes.set_title("title")
axes.plot(plt.contourf(xx, yy, Z,cmap=plt.cm.autumn, alpha=0.8))
canvas = FigureCanvas(figure)
canvas.setGeometry(0, 0, 500, 500)
scene.addWidget(canvas)
self.setScene(scene)