Mastering Scale Label Setting in Seaborn Heat Map
Introduction
In this tutorial, we will learn how to set the scale labels of the heat map in the Seaborn library, including setting custom labels, adjusting rotation labels, controlling font size, and even hiding labels, etc.
Without further ado, let’s get started!
For example
First, let’s take a look at an example. First, let’s import the libraries we need, as shown below:
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
Next, we use the following code to generate the data we need. The code is as follows:
np.random.seed(0)
data = np.random.rand(4, 6)
metrics = ['Metric A', 'Metric B', 'Metric C', 'Metric D']
days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
df = pd.DataFrame(data, index=metrics, columns=days)
Next, let’s draw our default heat map. The code is as follows:
plt.figure(figsize=(10, 4))
sns.heatmap(df, annot=True)
plt.show()
The results after running are as follows: