mjs*_*ier 5 matplotlib streamlit
在 Streamlit 应用程序中,当尝试使用与标准格式不同的格式绘制图形时,我会得到非常糟糕的分辨率。
例子:
import pandas as pd
import numpy as np
import streamlit as st
index = pd.date_range(start='2019-01-01', periods=31)
data = np.random.randint(0,100,size=(len(index)))
df = pd.DataFrame(index=index, data=data)
df.plot(figsize=(25, 5), antialiased=True)
st.pyplot(dpi=100)
Run Code Online (Sandbox Code Playgroud)
结果如下:
Jupyter Notebook 中具有相同 Figsize 的相同绘图不存在此问题。为什么会发生这种情况以及如何解决这个问题?
小智 5
我正在复制并粘贴您从 Streamlit 论坛收到的针对此问题的回复:
\n\n“嘿@mjspier - 感谢您查看 Streamlit!
\n\nFigsize 参数值以英寸为单位,因此在本例中,您生成的图像的宽度为 25 英寸。然后 Streamlit 将该图像缩小到 Streamlit\xe2\x80\x99s 最大可显示宽度,约为 1500 像素,因此会变得模糊。
\n\n一个简单的解决方法是传递一个小的无花果大小。(figsize 中的每英寸大约为 1000 像素,因此 figsize 为 (15, 3) 看起来不会那么模糊。)
\n\n我\xe2\x80\x99ve也打开了一个关于此的错误,这样我们至少会做一些比当figsize非常大时显示丑陋的图像更意外的事情。”
\n\n希望这可以帮助!
\n| 归档时间: |
|
| 查看次数: |
3973 次 |
| 最近记录: |