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

泪湿孤枕 提交于 2019-12-20 04:54:10

问题


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?


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/46234158/how-to-remove-x-and-y-axis-labels-in-a-clustermap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!