Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove the axis tick marks on seaborn heatmap

I have a seaborn heatmap but i need to remove the axis tick marks that show as dashes. I want the tick labels but just need to remove the dash (-) at each tick on both axes. My current code is:

sns.heatmap(df, annot=True, fmt='.2f', center=0)

enter image description here

I tried despine and that didnt work.

like image 795
deep_butter Avatar asked Apr 04 '19 02:04

deep_butter


People also ask

How do you remove axis labels in python?

Matplotlib removes both labels and ticks by using xaxis. set_visible() set_visible() method removes axis ticks, axis tick labels, and axis labels also.


2 Answers

@ImportanceOfBeingEarnest had a nice answer in the comments that I wanted to add as an answer (in case the comment gets deleted).

For a heatmap:

ax = sns.heatmap(df, annot=True, fmt='.2f', center=0)
ax.tick_params(left=False, bottom=False) ## other options are right and top

If this were instead a clustermap (like here How to remove x and y axis labels in a clustermap?), you'd have an extra call:

g = sns.clustermap(...)
g.ax_heatmap.tick_params(left=False, bottom=False)

And for anyone who wanders in here looking for the related task of removing tick labels, see this answer (https://stackoverflow.com/a/26428792/3407933).

like image 93
spacetyper Avatar answered Oct 13 '22 11:10

spacetyper


ax = sns.heatmap(df, annot=True, fmt='.2f', center=0)
ax.tick_params(axis='both', which='both', length=0)

ax is a matplotlib.axes object. All axes parameters can be changed in this object, and here's an example from the matplotlib tutorial on how to change tick parameters. both selects both x and y axis, and then their length is changed to 0, so that the ticks are not visible anymore.

like image 2
Smartens Avatar answered Oct 13 '22 11:10

Smartens