【问题标题】:matplotlib plot has bad resolution in streamlitmatplotlib plot 在 streamlit 中的分辨率很差
【发布时间】:2020-03-25 01:25:05
【问题描述】:

在流线型应用程序中,当尝试使用与标准格式不同的格式绘制图形时,我得到的分辨率非常差。

例子:

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)

结果如下:

具有相同 figsize 的 jupyter notebook 中的相同绘图没有此问题。 为什么会发生这种情况,我该如何解决这个问题?

【问题讨论】:

    标签: matplotlib streamlit


    【解决方案1】:

    我正在复制并粘贴您收到的以下问题的response from the Streamlit Forum

    “嘿@mjspier - 感谢您查看 Streamlit!

    figsize 参数值以英寸为单位,因此在这种情况下,您将生成一个预期为 25 英寸宽的图像。然后,Streamlit 将该图像缩小到 Streamlit 的最大可显示宽度,大约为 1500 像素,因此会出现模糊。

    一个简单的解决方法是传递一个小的 figsize。 (figsize 中的每英寸约为 1000 像素,因此 (15, 3) 的 figsize 看起来不那么模糊。)

    我还为此打开了一个错误,这样我们至少可以做一些比在 figsize 非常大时显示丑陋图像少出乎意料的事情。”

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2013-08-06
      • 2018-01-14
      • 1970-01-01
      • 1970-01-01
      • 2021-11-10
      • 2014-09-24
      • 2022-10-07
      • 2020-08-25
      • 2015-04-06
      相关资源
      最近更新 更多