Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
How to remove the axis tick marks on a Seaborn heatmap?
To remove the axis tick marks on a Seaborn heatmap, you can use the tick_params() method to customize the appearance of ticks and tick labels. This is useful when you want a cleaner visualization without the small lines indicating tick positions.
Basic Heatmap with Tick Marks
First, let's create a basic heatmap to see the default tick marks −
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
# Create sample data
data = np.random.rand(4, 4)
# Create heatmap
plt.figure(figsize=(6, 4))
ax = sns.heatmap(data, annot=True, cmap='viridis')
plt.title('Heatmap with Default Tick Marks')
plt.show()
Removing Tick Marks
Use tick_params() with left=False and bottom=False to remove the tick marks −
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
# Create sample data
data = np.random.rand(4, 4)
# Create heatmap and remove tick marks
plt.figure(figsize=(6, 4))
ax = sns.heatmap(data, annot=True, cmap='viridis')
ax.tick_params(left=False, bottom=False)
plt.title('Heatmap without Tick Marks')
plt.show()
Alternative Method Using Seaborn Parameters
You can also remove tick marks directly in the heatmap() function −
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
# Create sample data
data = np.random.rand(4, 4)
# Remove tick marks using heatmap parameters
plt.figure(figsize=(6, 4))
sns.heatmap(data, annot=True, cmap='viridis',
xticklabels=True, yticklabels=True)
plt.tick_params(left=False, bottom=False)
plt.title('Alternative Method')
plt.show()
Removing Both Tick Marks and Labels
To remove both tick marks and labels completely −
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
# Create sample data
data = np.random.rand(4, 4)
# Remove both tick marks and labels
plt.figure(figsize=(6, 4))
ax = sns.heatmap(data, annot=True, cmap='viridis',
xticklabels=False, yticklabels=False)
ax.tick_params(left=False, bottom=False)
plt.title('No Tick Marks or Labels')
plt.show()
Key Parameters
| Parameter | Description | Values |
|---|---|---|
left |
Controls left axis tick marks | True/False |
bottom |
Controls bottom axis tick marks | True/False |
right |
Controls right axis tick marks | True/False |
top |
Controls top axis tick marks | True/False |
Conclusion
Use ax.tick_params(left=False, bottom=False) to remove tick marks while keeping labels. For a completely clean heatmap, combine this with xticklabels=False and yticklabels=False parameters.
Advertisements
