Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
831 views
in Technique[技术] by (71.8m points)

python - How to remove x and y axis labels in a clustermap?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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("")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...