如何删除集群图中的 x 和 y 轴标签? [英] How to remove x and y axis labels in a clustermap?

查看:53
本文介绍了如何删除集群图中的 x 和 y 轴标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在基于 DataFrame 创建一个图:

I am creating a plot based on a DataFrame:

cg = sns.clustermap(df_correlations.T)

问题是 x 和 y 轴中有来自分层索引的不需要的标签.因此,我想尝试删除这些标签,例如像这样:

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

但这没有效果.如何删除 x 和 y 轴上的标签?

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

推荐答案

没有问题的 mcve 就很难知道标签来自哪里(我不知道数据框需要看起来像这样才能生成标签,因为默认情况下不应该有任何标签.)但是,可以使用已知的方法 .set_xlabel.set_ylabel.

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.

所以如果 g 是一个 ClusterGrid 实例,

So if g is a ClusterGrid instance,

g = sns.clustermap(...)

您可以通过

ax = g.ax_heatmap

然后使用您喜欢的任何方法来操作这个 matplotlib 轴.

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

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

这篇关于如何删除集群图中的 x 和 y 轴标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆