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.

1
  • If the suggested answer solved your problem, would you mind selecting it as the answer for your question? thanks Commented Apr 27, 2020 at 11:20

1 Answer 1

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...

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, I am using jupyter notebook. Even after using %matplotlib inline , I am getting an empty graph
I think the issue is with the animation. as described here you would need to use HTML5 video to render the animation...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.