Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import numpy as np
- import matplotlib
- matplotlib.use('Qt4Agg')
- import matplotlib.style
- from matplotlib.backends.backend_qt4agg import (
- Figure,
- FigureCanvasQTAgg as FigureCanvas)
- from PyQt4 import QtGui
- from PyQt4.uic import loadUiType
- Ui_MainWindow, QMainWindow = loadUiType('dialog.ui')
- matplotlib.style.use('ggplot')
- class Main(QMainWindow, Ui_MainWindow):
- def __init__(self, ):
- super(Main, self).__init__()
- self.setupUi(self)
- self.layout_mpl = QtGui.QVBoxLayout()
- self.widget_mpl.setLayout(self.layout_mpl)
- self.prepare_figure()
- # Assign callbacks
- self.button_refresh.clicked.connect(self.update_figure)
- def prepare_figure(self):
- self.fig = Figure()
- self.axes = self.fig.add_subplot(111)
- self.axes.set_xlim((0, 6))
- self.axes.set_xlabel('seq.index')
- self.axes.set_ylim((0, 100))
- self.axes.set_ylabel('observation')
- N = 5
- self.graph = self.axes.scatter(
- [] * N, [] * N, s=[np.pi*5**2] * N, color='seagreen', animated=True)
- self.canvas = FigureCanvas(self.fig)
- # w = self.widget_mpl.width()
- # h = self.widget_mpl.height()
- # self.canvas.setFixedSize(w, h)
- self.canvas.draw()
- self.layout_mpl.addWidget(self.canvas)
- self.bg = self.canvas.copy_from_bbox(self.axes.bbox)
- def update_figure(self):
- self.canvas.restore_region(self.bg)
- # Set data to be visualized
- self.graph.set_offsets([(i+1, d) for i, d in
- enumerate(np.random.rand(5)*100)])
- # Redraw
- self.axes.draw_artist(self.graph)
- self.canvas.blit(self.axes.bbox)
- if __name__ == '__main__':
- app = QtGui.QApplication(sys.argv)
- main = Main()
- main.show()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement