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)
I tried despine and that didnt work.
Matplotlib removes both labels and ticks by using xaxis. set_visible() set_visible() method removes axis ticks, axis tick labels, and axis labels also.
@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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With