0

What´s up everyone! Ultimately, I have been working with python,learning the basics of animations using matplotlib. The code is quite simple:

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

plt.style.use('fivethirtyeight')

x_vals = []
y_vals = []


index = count()

def animate(i):
    x_vals.append(next(index))
    y_vals.append(random.randint(0, 5))

    plt.cla() # cla: clear axis
    plt.plot(x_vals,y_vals)

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

When I compile the code, no error is found but for this comment:

/home/der/.local/lib/python3.8/site-packages/matplotlib/animation.py:973: UserWarning: Animation was deleted without rendering anything. This is most likely unintended. To prevent deletion, assign the Animation to a variable that exists for as long as you need the Animation.
  warnings.warn(
<Figure size 432x288 with 0 Axes>

How can I fix it? Your help is invaluable to me since I have been scrumbling for a week.

  • Your code works for me as is. What is your os? Maybe you have different library versions installed? I am testing it on linux, using python 3, matplotlib 3.4.2 and pandas 1.3.1 – Gonzalo Odiard Aug 05 '21 at 02:47
  • Indeed, I am running on Visual Studio Code. The terminal I used to do all the importings is on Windows Subsystem For Linux. All the library I have used are the same version as yours.python 3, matplotlib 3.4.2 and pandas 1.3.1 – Derick Blacido Aug 05 '21 at 16:16
  • There are other questions with similar problems in different environments https://stackoverflow.com/questions/44636104/matplotlib-animation-not-showing/44711187 and https://stackoverflow.com/questions/25333732/matplotlib-animation-not-working-in-ipython-notebook-blank-plot maybe you can try some of the proposed solutions – Gonzalo Odiard Aug 05 '21 at 21:11
  • Also, you can check different mathplotlib backends https://matplotlib.org/stable/tutorials/introductory/usage.html#backends – Gonzalo Odiard Aug 05 '21 at 21:13

0 Answers0