Closed mantielero closed 4 years ago
Could you try to reproduce the issue with this reduced snippet?
from numpy import arange, sin, pi
from time import time, sleep
import os
os.environ["GKS_WSTYPE"] = "gksqt"
from gr.pygr import plot
x = arange(0, 2 * pi, 0.01)
for i in arange(1, 200):
plot(x, sin(x + i / 10.0))
sleep(0.0001)
This snippet works fine
Thank you for testing that. That's odd, there seems to be some interaction between pylab and GR then? I have updated the example to switch the order and use matplotlib.pyplot directly. Could you please try whether you still have the issue of gksqt opening and closing?
from numpy import arange, sin, pi
from time import time, sleep
import os
os.environ["GKS_WSTYPE"] = "gksqt"
num_frames = 200
x = arange(0, 2 * pi, 0.01)
# create an animation using GR
from gr.pygr import plot
tstart = time()
for i in range(num_frames):
plot(x, sin(x + i / 10.0))
sleep(0.0001)
fps_gr = int(num_frames / (time() - tstart))
print('fps (GR): %4d' % fps_gr)
# create the same animation using matplotlib
from matplotlib.pyplot import plot, draw, pause
tstart = time()
line, = plot(x, sin(x))
for i in range(num_frames):
line.set_ydata(sin(x + i / 10.0))
draw()
pause(0.0001)
fps_mpl = int(num_frames / (time() - tstart))
print('fps (mpl): %4d' % fps_mpl)
print(' speedup: %6.1f' % (float(fps_gr) / fps_mpl))
Now it works fine:
$ python bench.py
fps (GR): 437
fps (mpl): 44
speedup: 9.9
I'm not sure what might be causing this interaction between the two libraries, but I'll update the example in the python-gr repo. Thank you for your help!
When I run this example, the GR part seems to close and create a new window per frame. This way it is very slow and there is no animation at all.