4

我想将我的实时绘图应用程序放入一个不错的 gtk3 程序中,到目前为止我得到了这个,但它没有显示窗口。我错过了什么?提前致谢!

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()
4

1 回答 1

2

使用canvas.draw()fig.canvas.draw()更新绘图。

有关更多详细信息,请参阅 matplotlib

于 2016-10-03T13:09:32.207 回答