简体   繁体   English

如何删除簇图中的x和y轴标签?

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

I am creating a plot based on a DataFrame : 我正在创建一个基于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. 问题是x和y轴上有不想要的标签,这些标签来自层次结构索引。 Thus I want to try and remove those labels eg 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? 如何删除x和y轴上的标签?

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. 没有这个问题,就很难知道标签来自何处(我不知道数据帧的外观如何,这样才能产生标签,因为默认情况下不应有任何标签。)但是,标签可以可以使用群集网格的热图轴的已知方法.set_xlabel.set_ylabel设置-因此也设置为空字符串。

So if g is a ClusterGrid instance, 因此,如果gClusterGrid实例,

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. 然后使用您喜欢的任何方法来操纵该matplotlib轴。

ax.set_xlabel("My Label")
ax.set_ylabel("")

尝试plt.axis('off') ,它可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM