如何删除集群图中的 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("")