Anyone has any idea why animation
is not working in Colab
?
MWE:
fig, ax = plt.subplots()
x = np.arange(0, 2*np.pi, 0.01)
line, = ax.plot(x, np.sin(x))
def init(): # only required for blitting to give a clean slate.
line.set_ydata([np.nan] * len(x))
return line,
def animate(i):
line.set_ydata(np.sin(x + i / 100)) # update the data.
return line,
ani = animation.FuncAnimation(
fig, animate, init_func=init, interval=2, blit=True, save_count=50)
plt.show()
I've tried using the notebook backend but to no avail. The only way I could get a plot was using rc('animation', html='jshtml')
and HTML(ani.to_jshtml())
. But, it produces two plots and one of them requires pressing the play button which is something I don't want. I need a plot to live update. How to achieve that?
HTML(ani.to_jshtml())
asv dev
to test out a benchmark
benchmarks/dates.py
file...
t = fig.text()
?
I've seen the below
plt.yticks(fontproperties=self.font_property)
But I'm not a fan because 1) it uses pyplot instead of my figure, and 2) it only does the primary axis or the secondary axis depending on calling order (probably can do both if I call it before and after .twinx()
)
Also, unrelated;
How does zorder magic work? I have some lines (zorder 2) on the primary axis (zorder 0.1), and a polycollection (zorder 1) on the secondary axis (zorder 0); my primary axis has gridlines. If I set those gridlines (ax.yaxis.get_gridlines()) to zorder 0.1 they are still on top of my poly; do I have to set some other attribute?