from matplotlib import pyplot as plt
from PyQt4.QtGui import QWidget, QVBoxLayout
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg
class Test(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.canvas = FigureCanvasQTAgg(self.test_fig())
self.layout = QVBoxLayout(self)
self.layout.addWidget(self.canvas)
while True:
self.update_fig()
def update_fig(self):
self.canvas.figure = self.test_fig()
self.canvas.draw()
def test_fig(self):
fig = plt.figure()
ax1 = fig.add_subplot(111)
line, = ax1.plot([1,2,3], [4,5,6])
return fig
if __name__ == "__main__":
import sys
from PyQt4.QtGui import QApplication
app = QApplication(sys.argv)
main = Test()
main.show()
app.exec_()