如何在streamlit中绘制gif?
我尝试在我的 Streamlit 网站上绘制 gif,但它没有生成任何内容。它不会给出任何错误,它只是将环境保持为空,就好像代码中没有运行任何内容一样。
下面我留下了负责 gif 情节的代码。
graph, = plt.plot([], [], color="gold", markersize=3, label='Tempo: 0 s')
L = plt.legend(loc=1)
plt.close() # Não mostra a imagem de fundo
def animate(i):
lab = 'Tempo: ' + str(round(dt*i * (rs_sun / 2.0) * 3e-5 , -int(math.floor(math.log10(abs(dt*(rs_sun / 2.0)*3e-5)))))) + ' s'
graph.set_data(x[:i], y[:i])
L.get_texts()[0].set_text(lab) # Atualiza a legenda a cada frame
return graph,
skipframes = int(len(x)/200)
if skipframes == 0:
skipframes = 1
ani1 = animation.FuncAnimation(fig, animate, frames=range(0,len(x),skipframes), interval=30, blit = True, repeat = False)
plt.show()
I tried to plot a gif on my streamlit site, but it doesn’t generate anything. It doesn’t give any error, it just keeps the environment empty as if nothing had been run in the code.
Below I left the piece of my code responsible by the plot of the gif.
graph, = plt.plot([], [], color="gold", markersize=3, label='Tempo: 0 s')
L = plt.legend(loc=1)
plt.close() # Não mostra a imagem de fundo
def animate(i):
lab = 'Tempo: ' + str(round(dt*i * (rs_sun / 2.0) * 3e-5 , -int(math.floor(math.log10(abs(dt*(rs_sun / 2.0)*3e-5)))))) + ' s'
graph.set_data(x[:i], y[:i])
L.get_texts()[0].set_text(lab) # Atualiza a legenda a cada frame
return graph,
skipframes = int(len(x)/200)
if skipframes == 0:
skipframes = 1
ani1 = animation.FuncAnimation(fig, animate, frames=range(0,len(x),skipframes), interval=30, blit = True, repeat = False)
plt.show()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Streamlit 仅允许使用
st.image(img)
发送 .jpg 和 .png 图像,但有一种方法可以发布 GIF。这就是我在我的应用程序上所做的:
Streamlit only allows .jpg and .png images using
st.image(img)
, but there's a way you can post GIF's.That's how I have done on my app: