1

I am trying to plot a dynamic figure with drawnow inside a gtk window. For example, this one

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)

I have seen that for static figures using matplotlib is posible:

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

But the thing is that I want a dynamic figure. I don't see how can I do this. Please help

oldtechaa
  • 1,463
  • 1
  • 14
  • 26
Dau
  • 419
  • 1
  • 5
  • 20
  • What does "dynamic" mean in your case? Does it mean user-interactive? Does it mean varies over time? Or something else? – andlabs Jan 03 '17 at 16:06
  • it means the graphic changes in every iteration. Like the example – Dau Jan 04 '17 at 04:33
  • And how long is each iteration? I can't tell if there's any time between frames, or if the end result of that first example is the plot flashing before you in less than a second. Whatever the case, since this is inherently an animation, you'll need to set up a timer. Look up the Python equivalent of `g_timeout_add()`. – andlabs Jan 04 '17 at 12:55

0 Answers0