简体   繁体   English

如何在流光中显示热图颜色相关性 plot

[英]how to display heatmap color correlation plot in streamlit

I'm trying to do visualization with streamlit.one of the contents I have is correlation like this:我正在尝试使用 streamlit 进行可视化。我拥有的内容之一是这样的相关性: 在此处输入图像描述 But I want it to have color like heatmap plot但我希望它具有像热图 plot 这样的颜色

this is my correlation code这是我的相关代码

df_col = pd.concat([df5, df6,df7,df8,df9], axis=1)
    df5.columns = ['month', 'price_kcl', 'change_kcl']
    df6.columns = ['month_fosfat', 'price_fosfat', 'change_fosfat']
    df7.columns = ['month_bb', 'price_bara', 'change_bb']
    df8.columns = ['month_urea', 'price_urea', 'change_urea']
    df9.columns = ['month_npk', 'price_npk', 'change_npk']
    df_col = pd.concat([df5, df6,df7,df8,df9], axis=1)
    df5.columns = ['month', 'price_kcl', 'change_kcl']
    df6.columns = ['month_fosfat', 'price_fosfat', 'change_fosfat']
    df7.columns = ['month_bb', 'price_bara', 'change_bb']
    df8.columns = ['month_urea', 'price_urea', 'change_urea']
    df9.columns = ['month_npk', 'price_npk', 'change_npk']
    df_col = df_col.set_index('month')
    df_corr = df_col.corr()
    st.write(df_corr)
    plt.matshow(df_col.corr())

thank you in advance!先感谢您!

You can write Matplotlib figures in Streamlit.您可以在 Streamlit 中编写 Matplotlib 数字。 You only have to modify your code slightly:您只需稍微修改您的代码:

import seaborn as sns
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
sns.heatmap(df_col.corr(), ax=ax)
st.write(fig)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM