gpt4 book ai didi

matplotlib - sns.clustermap 刻度丢失

转载 作者:行者123 更新时间:2023-12-04 02:26:57 25 4
gpt4 key购买 nike

我正在尝试可视化 CNN 文本分类模型中正在学习的过滤器。为此,我在卷积层之后立即提取了文本样本的特征图,对于大小为 3 的过滤器,我得到了一个 (filter_num)*(length_of_sentences) 大小的张量。

df = pd.DataFrame(-np.random.randn(50,50), index = range(50), columns= range(50))
g= sns.clustermap(df,row_cluster=True,col_cluster=False)
plt.setp(g.ax_heatmap.yaxis.get_majorticklabels(), rotation=0) # ytick rotate
g.cax.remove() # remove colorbar
plt.show()
此代码导致:
heatmap

Where I can't see all the ticks in the y-axis. This is necessarybecause I need to see which filters learn which information. Is thereany way to properly exhibit all the ticks in the y-axis?

最佳答案

kwargs来自 sns.clustermap转至 sns.heatmap ,它有一个选项 yticklabels ,其 documentation状态(强调我的):

If True, plot the column names of the dataframe. If False, don’t plot the column names. If list-like, plot these alternate labels as the xticklabels. If an integer, use the column names but plot only every n label. If “auto”, try to densely plot non-overlapping labels.



在这里,最简单的选择是将其设置为整数,因此它将绘制每个 n标签。我们想要每个标签,所以我们想把它设置为 1 , IE。:
g = sns.clustermap(df, row_cluster=True, col_cluster=False, yticklabels=1)

在您的完整示例中:
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np

df = pd.DataFrame(-np.random.randn(50,50), index=range(50), columns=range(50))
g = sns.clustermap(df, row_cluster=True, col_cluster=False, yticklabels=1)
plt.setp(g.ax_heatmap.yaxis.get_majorticklabels(), rotation=0) # ytick rotate
g.cax.remove() # remove colorbar

plt.show()

enter image description here

关于matplotlib - sns.clustermap 刻度丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51074276/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com