1

我正在尝试在 gtk 窗口内绘制一个带有 drawow 的动态图形。比如这个

from pylab import arange, plt
import numpy as np
from drawnow import drawnow

plt.ion() # enable interactivity
fig=plt.figure() # make a figure

def makeFig():
    plt.scatter(x,y) # I think you meant this

x=list()
y=list()

for i in arange(1000):
    temp_y=np.random.random()
    x.append(i)
    y.append(temp_y) # or any arbitrary update to your figure's data
    i+=1
    drawnow(makeFig)

我已经看到,对于使用 matplotlib 的静态数字是可能的:

import gtk

from matplotlib.figure import Figure
from numpy import arange, sin, pi

# uncomment to select /GTK/GTKAgg/GTKCairo
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas



win = gtk.Window()
win.connect("destroy", lambda x: gtk.main_quit())
win.set_default_size(400, 300)
win.set_title("Embedding in GTK")

f = Figure(figsize=(5, 4), dpi=100)
a = f.add_subplot(111)
t = arange(0.0, 3.0, 0.01)
s = sin(2*pi*t)
a.plot(t, s)

canvas = FigureCanvas(f)  # a gtk.DrawingArea
win.add(canvas)

win.show_all()
gtk.main() 

但问题是我想要一个动态的数字。我不明白我该怎么做。请帮忙

4

0 回答 0