how to display heatmap color correlation plot in streamlit
Asked Answered
B

1

5

I'm trying to do visualization with streamlit.one of the contents I have is correlation like this: enter image description hereBut I want it to have color like heatmap 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!

Bumper answered 24/1, 2021 at 14:13 Comment(0)
C
11

You can write Matplotlib figures in Streamlit. 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)
Cologarithm answered 24/1, 2021 at 17:33 Comment(2)
thank you!but i got this error "corr() got an unexpected keyword argument 'ax'"what does this mean?Bumper
Sorry, I forgot the heatmap. Now I updated the answerCologarithm

© 2022 - 2024 — McMap. All rights reserved.