- #91 Custom seaborn heatmap
- #91 Custom seaborn heatmap
- #91 Custom seaborn heatmap
- #91 Custom seaborn heatmap
The graph #90 explains how to make a heatmap from 3 different input formats. In this post, I describe how to customize the appearance of these heatmaps. These 4 examples start by importing libraries and making a data frame:
# library import seaborn as sns import pandas as pd import numpy as np # Create a dataset (fake) df = pd.DataFrame(np.random.random((10,10)), columns=["a","b","c","d","e","f","g","h","i","j"])
- 1/ Annotate each cell with value
-
annot=True will add a label into each cell, providing the exact value behind the color.
sns.heatmap(df, annot=True, annot_kws={"size": 7}) #sns.plt.show()
- 2/ Custom grid lines
-
sns.heatmap(df, linewidths=2, linecolor='yellow') #sns.plt.show()
- 3/ Remove X or Y labels
-
yticklabels and xticklabels control the presence / abscence of labels for the Y and X axis respectively.
sns.heatmap(df, yticklabels=False) #sns.plt.show()
- 4/ Remove color bar
-
Code is self explanatory.
sns.heatmap(df, cbar=False) #sns.plt.show()
- 5/ Hide a few axis labels to avoid overlapping
-
With the xticklabels(x) you can keep one label every x labels:
sns.heatmap(df, xticklabels=4) #sns.plt.show()
I congratulate you to this great framework. It offers much more than I could imagine.
It helped me a lot to create a pretty dashboard on energy consumption.
even terms such as heatmap are more expressive than pcolor.
The only feature I’m missing is relabeling the axis of a heatmap.
This is important for me in subplots, e.g. relabeling xaxis from 1-365 days to 1-12 months.