I would like to animate a fitness function graph to debug my algorithm behavior. However, as soon as the plot is added to the page, it becomes a static image and no longer refreshes.
Any ideas on how to animate a line chart?
I also couldn’t find if I can reuse a plot slot to manually set a new graph.
import matplotlib.pyplot as plt import matplotlib.animation as animation import numpy as np import streamlit as st fig, ax = plt.subplots() max_x = 5 max_rand = 10 x = np.arange(0, max_x) ax.set_ylim(0, max_rand) line, = ax.plot(x, np.random.randint(0, max_rand, max_x)) def init(): # give a clean slate to start line.set_ydata([np.nan] * len(x)) return line, def animate(i): # update the y values (every 1000ms) line.set_ydata(np.random.randint(0, max_rand, max_x)) return line, ani = animation.FuncAnimation( fig, animate, init_func=init, interval=1000, blit=True, save_count=10) st.pyplot(plt)