I’m trying to do visualization with streamlit.one of the contents I have is correlation like this:
But I want it to have color like heatmap plot
this is my correlation code
JavaScript
x
17
17
1
df_col = pd.concat([df5, df6,df7,df8,df9], axis=1)
2
df5.columns = ['month', 'price_kcl', 'change_kcl']
3
df6.columns = ['month_fosfat', 'price_fosfat', 'change_fosfat']
4
df7.columns = ['month_bb', 'price_bara', 'change_bb']
5
df8.columns = ['month_urea', 'price_urea', 'change_urea']
6
df9.columns = ['month_npk', 'price_npk', 'change_npk']
7
df_col = pd.concat([df5, df6,df7,df8,df9], axis=1)
8
df5.columns = ['month', 'price_kcl', 'change_kcl']
9
df6.columns = ['month_fosfat', 'price_fosfat', 'change_fosfat']
10
df7.columns = ['month_bb', 'price_bara', 'change_bb']
11
df8.columns = ['month_urea', 'price_urea', 'change_urea']
12
df9.columns = ['month_npk', 'price_npk', 'change_npk']
13
df_col = df_col.set_index('month')
14
df_corr = df_col.corr()
15
st.write(df_corr)
16
plt.matshow(df_col.corr())
17
thank you in advance!
Advertisement
Answer
You can write Matplotlib figures in Streamlit. You only have to modify your code slightly:
JavaScript
1
7
1
import seaborn as sns
2
import matplotlib.pyplot as plt
3
4
fig, ax = plt.subplots()
5
sns.heatmap(df_col.corr(), ax=ax)
6
st.write(fig)
7