osx - Animating plots on ipython 2 for mac os -
osx - Animating plots on ipython 2 for mac os -
i'm attempting animate (at run time) unlike answer in mac os , ipython notebook 2.0. have next code:
%pylab inline import time, sys import numpy np import matplotlib.pyplot plt ipython.display import clear_output f, ax = plt.subplots() x = np.linspace(0,6,200) in range(10): y = i/10*np.sin(x) print ax.plot(x,y) time.sleep(0.1) clear_output(true) display(f) ax.cla() # turn off if you'd "build up" plots plt.close() which seems work, print working without flashing (a previous problem, corrected clear_output), axes not updating.
the issue here i integer, line y = i/10*np.sin(x) integer division, returns 0. animating! result flat line @ 0. alter line to
y = float(i)/10*np.sin(x) when that, you'll notice doesn't animate in nice way. create better, can explicitly set y-axis limits instead of letting matplotlib automatically. within loop, add together line
ax.set_ylim(-1, 1) the final code below animates nicely.
%pylab inline import time, sys import numpy np import matplotlib.pyplot plt ipython.display import clear_output f, ax = plt.subplots() x = np.linspace(0,6,200) in range(10): y = float(i)/10*np.sin(x) print ax.set_ylim(-1, 1) ax.plot(x,y) time.sleep(0.1) clear_output(true) display(f) ax.cla() # turn off if you'd "build up" plots plt.close() osx ipython-notebook
Comments
Post a Comment