How to remove X or Y labels from a Seaborn heatmap?

To remove X or Y labels from a Seaborn heatmap, you can use the xticklabels and yticklabels parameters. Setting them to False removes the axis labels while keeping the data visualization intact.

Removing Y-axis Labels

Use yticklabels=False to hide row labels ?

import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = [8, 4]
plt.rcParams["figure.autolayout"] = True

# Create sample data
data = np.random.random((5, 5))
df = pd.DataFrame(data, columns=["col1", "col2", "col3", "col4", "col5"])

# Create heatmap without Y-axis labels
sns.heatmap(df, yticklabels=False)
plt.title("Heatmap without Y-axis Labels")
plt.show()

Removing X-axis Labels

Use xticklabels=False to hide column labels ?

import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = [8, 4]

# Create sample data
data = np.random.random((5, 5))
df = pd.DataFrame(data, columns=["col1", "col2", "col3", "col4", "col5"])

# Create heatmap without X-axis labels
sns.heatmap(df, xticklabels=False)
plt.title("Heatmap without X-axis Labels")
plt.show()

Removing Both X and Y Labels

Set both parameters to False for a clean heatmap ?

import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = [8, 4]

# Create sample data
data = np.random.random((5, 5))
df = pd.DataFrame(data, columns=["col1", "col2", "col3", "col4", "col5"])

# Create heatmap without any axis labels
sns.heatmap(df, xticklabels=False, yticklabels=False)
plt.title("Heatmap without Any Axis Labels")
plt.show()

Customizing Label Display

You can also control label frequency by passing integers ?

import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

# Create larger sample data
data = np.random.random((10, 10))
df = pd.DataFrame(data)

# Show every 2nd label
sns.heatmap(df, xticklabels=2, yticklabels=2)
plt.title("Heatmap with Every 2nd Label")
plt.show()

Parameters Summary

Parameter Value Effect
xticklabels False Removes column labels
yticklabels False Removes row labels
xticklabels Integer (e.g., 2) Shows every nth column label
yticklabels Integer (e.g., 2) Shows every nth row label

Conclusion

Use xticklabels=False and yticklabels=False to remove axis labels from Seaborn heatmaps. You can also pass integers to control label frequency for large datasets.

Updated on: 2026-03-25T21:51:49+05:30

9K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements