Hi,
I have tested the example (I think I did see it in a blog post), Streamlit loads the graph, but nothing gets displayed.
And then the following error gets displayed, due to the exit function (Its supposed to happen):
My Code example:
import mplfinance as mpf
import matplotlib.animation as animation
…A bunch of functions that get a pandas dataframe…
df = data
pkwargs=dict(type=‘candle’, tz_localize=False)
plt.style.use(‘fivethirtyeight’)
fig, axes = mpf.plot(data.iloc[0:20],returnfig=True,volume=False,
figsize=(11,8),
title=’\n\nLive Data’,
**pkwargs)
ax_main = axes[0]
ax_emav = ax_main
def animate(ival):
if (20+ival) > len(df):
print(‘no more data to plot’)
ani.event_source.interval *= 3
if ani.event_source.interval > 600000:
exit()
return
data = df.iloc[ival:(20 + ival)]
data_c = data.copy()
df_reg = reg_calc(data_c, ival)
ValB, ValS = function_to_calculate_extra_stuff(df_reg)
df_reg[‘ValA’] = Buy
df_reg[‘ValB’] = Sell
df_reg_c = df_reg
reg_plot = [
mpf.make_addplot(df_reg_c['Hreg'], ax=ax_emav, type='line', color='g'),
mpf.make_addplot(df_reg_c['Lreg'], ax=ax_emav, type='line', color='r'),
mpf.make_addplot(df_reg_c['ValA'], ax=ax_emav, type='scatter',markersize=200,marker='^', color='b'),
mpf.make_addplot(df_reg_c['ValB'], ax=ax_emav, type='scatter',markersize=200,marker='v',color='black'),
]
ax_main.clear()
ax_emav.clear()
mc = mpf.make_marketcolors(up='g', down='r')
s = mpf.make_mpf_style(marketcolors=mc)
mpf.plot(data, ax=ax_main, addplot=reg_plot, style=s, **pkwargs)
ani = animation.FuncAnimation(fig, animate, interval=1000)
st.markdown(“Simple animation examples — Matplotlib 2.1.2 documentation”)
components.html(ani.to_jshtml(), height=1000)
I hope that it makes sense. I really have been trying to get this to work on Streamlit.