我想增加 searborn clustermap 行的最大符号数

问题描述

Please look at the "-" on the right

有200多行,但实际显示的“-”似乎连100个都没有。

如何使用 seaborn 的 clustermap 来显示所有行的标签

解决方法

可以保存clustermap的grid,然后访问底层的grid.ax_heatmap来调用set_ticks()set_ticklabels()

这是将 ytick 间隔降低到 20 的示例。您可以根据数据需要更改 interval 变量。

import seaborn as sns
import numpy as np
iris = sns.load_dataset('iris')
species = iris.pop('species')

# save grid object
grid = sns.clustermap(iris)

# adjust tick interval as desired
interval = 20

# create custom ytick array
bottom,top = grid.ax_heatmap.get_ylim()
yticks = np.arange(min(bottom,top),max(bottom,interval)

# set ticks and ticklabels on underlying ax_heatmap
grid.ax_heatmap.yaxis.set_ticks(yticks)
grid.ax_heatmap.yaxis.set_ticklabels(yticks)

iris clustermap with ytick interval of 20