How to create a live updating matplotlib graph in gtk3
我想将实时绘图应用程序放到一个不错的gtk3程序中,到目前为止,我已经知道了,但是它没有显示窗口。我想念什么?在此先感谢!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import serial import numpy as np from matplotlib.figure import Figure from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo as FigureCanvas from gi.repository import Gtk class MyWindow(Gtk.ApplicationWindow): def __init__(self): Gtk.Window.__init__(self, title="Toolbar Example") self.set_size_request(700, 500) self.box = Gtk.Box(spacing=6, orientation=Gtk.Orientation.VERTICAL) self.add(self.box) fig = Figure() ax = fig.add_subplot(111) ax.set_xlim(0, 50) ax.set_ylim(0, 20) ydata = [0] * 50 line, = ax.plot(ydata, label='ydata') ax.legend() f = FigureCanvas(fig) self.box.pack_start(f, True, True, 0) while True: ydata.append(10) line.set_data(np.arange(len(ydata)), ydata) f.draw() win = MyWindow() win.connect("delete-event", Gtk.main_quit) win.show_all() Gtk.main() |
使用
有关更多详细信息,请参见matplotlib。