Home > Blockchain >  pivot table in proper order for the heatmap
pivot table in proper order for the heatmap

Time:11-15

while creating a heatmap I have following syntax:

import matplotlib.pyplot as plt
import seaborn as sns
sns.set_theme()
data=df.rename(columns={0:'Year', 1:'Month', 2:'Count'})
data= pd.pivot_table(data, values='Count', index='Year', columns='Month')
f, ax = plt.subplots(figsize=(15, 6))
sns.heatmap(data, annot=True, fmt="d", linewidths=.5, ax=ax)

and that generates following heatmap:

enter image description here

What I want is ascending or descending order of month along x-axis. That is Jan, Feb, Mar, etc. How do I accomplish like enter image description here

  • Related