【问题标题】:How to plot a gif in streamlit?如何在streamlit中绘制gif?
【发布时间】:2022-06-22 04:11:46
【问题描述】:

我试图在我的流线型网站上绘制一个 gif,但它没有生成任何东西。它不会给出任何错误,它只是保持环境为空,就好像代码中没有运行任何内容一样。

下面我把我的代码responsabel 留给了 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()

【问题讨论】:

    标签: python matplotlib animation gif streamlit


    【解决方案1】:

    请注意,您在代码中的 cmets 是用葡萄牙语编写的。我是巴西人,但由于我们在 stackoverflow.com,所以我会用英语回复!

    Streamlit 仅允许使用 st.image(img) 的 .jpg 和 .png 图像,但有一种方法可以发布 GIF。

    这就是我在我的应用上所做的:

    file = open(r"path", 'rb')
    contents = file.read()
    data_url = base64.b64encode(contents).decode('utf-8-sig')
    file.close()
    st.markdown(f'<img src="data:image/gif;base64,{data_url}>',unsafe_allow_html = True)
    

    Espero que funcione para você。

    【讨论】:

      猜你喜欢
      • 2021-08-05
      • 2021-07-01
      • 2014-04-10
      • 2021-07-15
      • 2021-07-18
      • 2020-10-26
      • 2021-05-12
      • 2014-01-22
      • 1970-01-01
      相关资源
      最近更新 更多