1

I currently try to use matplotlib.animation.FuncAnimation to create Dynamic candlestick, but when I Use the example code like this link.

My python version is 3.7.1

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

fig, ax = plt.subplots()
xdata, ydata = [], []
ln, = plt.plot([], [], 'ro')

def init():
    ax.set_xlim(0, 2*np.pi)
    ax.set_ylim(-1, 1)
    return ln,

def update(frame):
    xdata.append(frame)
    ydata.append(np.sin(frame))
    ln.set_data(xdata, ydata)
    return ln,

ani = FuncAnimation(fig, update, frames=np.linspace(0, 2*np.pi, 128),
                    init_func=init, blit=True)
plt.show()

But as images, I get an empty figure. enter image description here

I don't know what's happened.

So I come to here ask your help.

All you guys responses are very helpful to me, It means a lot. Thanks.

leonheess
  • 16,068
  • 14
  • 77
  • 112
Dean Lin
  • 11
  • 2
  • Plots in Jupyter are of the `png` format. So it won't be animated. Have a look at [this answer](https://stackoverflow.com/questions/43445103/inline-animations-in-jupyter). Your code runs fine in a Python interpreter terminal. – funie200 Nov 16 '20 at 08:52
  • @funie200 it's kind of strange, I remember that I used to plot gif in jupyter notebook, I think there something wrong in my brain, Thanks a lot. – Dean Lin Nov 16 '20 at 09:07

1 Answers1

0

I found the reasons that I can run Animation in jupyter-notebook before.

I use the interact function which in ipywidgets module.

And this function need to use an interactive backend; %matplotlib notebook

Somehow I open my old Animation code and %matplotlib notebook is missing.

So I can't run my Animation.

It will be like this result in images.

enter image description here

Again, thanks StackOverflow a lot.

Dean Lin
  • 11
  • 2