MatplotLib Animation: Decay example with streamlit, nothing plotted

I have enclosed a code, which is basically the decay example of Matplotlib animation class, which is supposed to plot an animating sine wave, decaying, which runs fine when running the script from Spyder, but then when comment out and try running it with steamlit, the axes show on the page, but no plot is being drawn.


import itertools

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import streamlit as st

drawing1= st.empty()

def data_gen():
    for cnt in itertools.count():
        t = cnt / 10
        yield t, np.sin(2*np.pi*t) * np.exp(-t/10.)

def init():
    ax.set_ylim(-1.1, 1.1)
    ax.set_xlim(0, 10)
    del xdata[:]
    del ydata[:]
    line.set_data(xdata, ydata)
    return line,

fig, ax = plt.subplots()
line, = ax.plot([], [], lw=2)
xdata, ydata = [], []

#the_plot = st.pyplot(plt)

def run(data):
    # update the data
    t, y = data
    xmin, xmax = ax.get_xlim()

    if t >= xmax:
        ax.set_xlim(xmin, 2*xmax)
    line.set_data(xdata, ydata)

    return line,

ani = animation.FuncAnimation(fig, run, data_gen, interval=10, init_func=init)