1

Simple matplotlib plot. Here is my code

from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimation
from itertools import count
import random

x = []
y = []
index=count()
def animate(i):
    x.append(next(index))
    y.append(random.randint(0,10))
    plt.plot(x,y)

a = FuncAnimation(plt.gcf(),animate,interval=1000)
plt.tight_layout()
plt.show()

Running the code above I get

<Figure size 576x396 with 0 Axes>

but no chart appears.

lhd
  • 436
  • 4
  • 16
Joseph arasta
  • 161
  • 1
  • 3
  • 12
  • If the suggested answer solved your problem, would you mind selecting it as the answer for your question? thanks – lhd Apr 27 '20 at 11:20

1 Answers1

0

Are you using Jupyter notebooks to run it? I tried with native libraries and it works just fine. The plots are visible.

Checking here i see the same situation. Could you try to use %matplotlib inline before importing matplotlib as:

%matplotlib inline # this line before importing matplotlib
from matplotlib import pyplot as plt

That said, the animation can be displayed using JavaScript. This is similar to the ani.to_html5() solution, except that it does not require any video codecs.

from IPython.display import HTML
HTML(a.to_jshtml())

this answer brings a more complete overview...

lhd
  • 436
  • 4
  • 16
  • Yes, I am using jupyter notebook. Even after using %matplotlib inline , I am getting an empty graph – Joseph arasta Apr 24 '20 at 08:12
  • I think the issue is with the animation. as described [here](http://louistiao.me/posts/notebooks/embedding-matplotlib-animations-in-jupyter-as-interactive-javascript-widgets/) you would need to use HTML5 video to render the animation... – lhd Apr 24 '20 at 08:26