7

I am creating a plot based on a DataFrame:

cg = sns.clustermap(df_correlations.T)

The problem is that the x and y axis have unwanted labels in it which come from a hierarchical index. Thus I want to try and remove those labels e.g. like this:

ax = cg.fig.gca()
ax.set_xlabel('')
ax.set_ylabel('')

But this has no effect. How can I remove the labels on the x and y axis?

Stefan Falk
  • 23,898
  • 50
  • 191
  • 378

3 Answers3

13

Without a mcve of the issue it's hard to know where the labels come from (I don't know how the dataframe needs to look like such that labels are produced, because by default there should not be any labels.) However, the labels can be set - and therefore also set to an empty string - using the known methods .set_xlabel and .set_ylabel of the heatmap axes of the cluster grid.

So if g is a ClusterGrid instance,

g = sns.clustermap(...)

you can get the heatmap axes via

ax = g.ax_heatmap

and then use any method you like to manipulate this matplotlib axes.

ax.set_xlabel("My Label")
ax.set_ylabel("")
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • 1
    Thanks, this worked. By the way I realized that another solution would be to set `df.index.names` and `df.columns.names` (or `name` depending on single or multi-index/columns) in order to get the correct names. – Stefan Falk Sep 17 '17 at 18:09
6

Turn off xticklabel, and yticklabel will address your problem.

sns.clustermap(df,yticklabels=False,xticklabels=False)
YGao
  • 59
  • 1
  • 3
1

try plt.axis('off'), it may solve your problem.

Odin
  • 1,914
  • 10
  • 5