'FuncAnimation' object has no attribute 'savefig'

hy guys , i hope you can help me :slight_smile: so i am trying to show a graph on streamlit
but i keep seeing this message (‘FuncAnimation’ object has no attribute ‘savefig’)whenever i rerun the app. Any idea how can i fix it?

Hey @oumaima,

I suppose you are trying to save a Matplotlib figure on disk, but what you actually build is a Matplotlib animation so it can’t be saved using the savefig method.

To save a Matplotlib animation, you’ll need to use a more specific writer to convert to a movie file or HTML file. You’ll find details on this page.

Could you share the bit of code that builds the Matplotlib animation and saves it on disk? If you’re able to make a small reproducible snippet, this would be really helpful to debug further!

Have a nice day,
Fanilo

well my main concern is to show it on the site.here is my code:

from itertools import count
import pandas as pd
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

plt.style.use('fivethirtyeight')

x_vals = []
y_vals = []

index = count()


def animate(i):
    data = pd.read_csv('data.csv')
    x = data['date']
    y = data['price']

    plt.cla()

    plt.plot(x[(len(x)-1-365):], y[(len(y)-1-365):], label='Bitcoin Price by $', linewidth=2)

    plt.legend(loc='upper left')
    plt.tight_layout()


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

plt.tight_layout()
plt.savefig('img&&',dpi=100)
plt.show()