如何在streamlightpython中将ggplot生成的图形保存为图像

2024-05-26 21:51:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我画了一张ggplot图。现在我想在我的Streamlight应用程序中提供下载图形作为图像选项。你知道怎么做吗

这是我的ggplot代码

 A = A + geom_line(data = pred1,mapping = aes(x = 'time',y = 'U_CI'),color = "red",linetype = "dotted",size = 1.3)\
                            +geom_line(data = pred2,mapping = aes(x = 'time',y = 'U_CI'),color = "blue",linetype = "dotted",size = 1.3)\
                            +geom_line(data = pred3,mapping = aes(x = 'time',y = 'U_CI'),color = "green",linetype = "dotted",size = 1.3)\
                            +geom_line(data = pred1,mapping = aes(x = 'time',y = 'L_CI'),color = "red",linetype = "dotted",size = 1.3)\
                            +geom_line(data = pred2,mapping = aes(x = 'time',y = 'L_CI'),color = "blue",linetype = "dotted",size = 1.3)\
                            +geom_line(data = pred3,mapping = aes(x = 'time',y = 'L_CI'),color = "green",linetype = "dotted",size = 1.3)

Tags: cidatasizetimelineredmappingcolor
1条回答
网友
1楼 · 发布于 2024-05-26 21:51:57

较新版本配有下载功能:

pip install  upgrade streamlit

with open("flower.png", "rb") as file:
     btn = st.download_button(
             label="Download image",
             data=file,
             file_name="flower.png",
             mime="image/png"
           )

但我建议使用plotly,streamlight也支持plotly,并且在每个图形上都有一个“下载为…”按钮&燃气轮机https://plotly.com/python/static-image-export/

enter image description here

相关问题 更多 >

    热门问题