Afternoon All,
I'm looking to create a heatmap of one column in my df. So inc_Year_Month
on y axis and Count
on the x axis
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
data = {
'inc_Year_Month':['2020-07','2020-08','2020-09','2020-10','2020-11','2020-12','2021-01','2021-02','2021-03','2021-04'],
'Count':[2,4,6,8,10,12,30,50,60,100],
}
dfTemp = pd.DataFrame(dict(data))
print(dfTemp)
dfTemp2 = np.asarray(dfTemp).reshape(dfTemp.shape[0],1)
df_heatmap = sns.heatmap(dfTemp2, annot=True, fmt="g", cmap='magma')
# df_heatmap = sns.heatmap(dfTemp2,cmap=ListedColormap(['green', 'yellow', 'red']))
df_heatmap_Figure = df_heatmap.get_figure()
# # Set to high resolution and save
df_heatmap_Figure.savefig('Hi Res Seaborn-heatmap2.png', dpi=300)
I get the error:
ValueError: cannot reshape array of size 20 into shape (10,1)
I thought I could resolve this by forcing the rectangular 2D dataset into an ndarray:
dfTemp2 = np.asarray(dfTemp).reshape(dfTemp.shape[0],1)