如何在 Seaborn Python 中转置单列热图的轴

问题描述 投票:0回答:0

我正在尝试在 Seaborn Python 中转置 Nx1 热图的轴。

当前状态如下: enter image description here

为此,我使用了以下内容:

# Heat map

# creating the plot
plt.subplots(figsize=(8,5))

# creating heatmap
ax = sb.heatmap(bbt_pd1.corr().loc[['Games_Won'],:], linewidths=1, linecolor='black', cmap="YlGnBu", annot=True, cbar_kws={'label': 'Correlation Coefficient', 'shrink': 0.6})
ax.figure.axes[-1].yaxis.label.set_size(12)
ax.figure.axes[-1].yaxis.label.set_color('navy')
ax.invert_yaxis()

# plotting and displaying final output
plt.xlabel('Games Won', fontsize=12, fontweight='bold',color='navy')
plt.ylabel('Variables for Analysis', fontsize=12, fontweight='bold',color='navy')
plt.title('Heatmap Analysis', fontsize=14, fontweight='bold',color='navy')
plt.show()

# ignoring warnings from output
warnings.filterwarnings("ignore")

现在,我只是想转置轴 - X 轴应该显示 Games Won,Y 轴应该包含所有变量。

我尝试在数据框上使用 T 函数并得到错误:

# Heat map

# creating the plot
plt.subplots(figsize=(8,5))

# creating heatmap
ax = sb.heatmap(bbt_pd1.**transpose()**.corr().loc[['Games_Won'],:], linewidths=1, linecolor='black', cmap="YlGnBu", annot=True, cbar_kws={'label': 'Correlation Coefficient', 'shrink': 0.6})
ax.figure.axes[-1].yaxis.label.set_size(12)
ax.figure.axes[-1].yaxis.label.set_color('navy')
ax.invert_yaxis()

# plotting and displaying final output
plt.xlabel('Games Won', fontsize=12, fontweight='bold',color='navy')
plt.ylabel('Variables for Analysis', fontsize=12, fontweight='bold',color='navy')
plt.title('Heatmap Analysis', fontsize=14, fontweight='bold',color='navy')
plt.show()

# ignoring warnings from output
warnings.filterwarnings("ignore")

错误:::

“[Index(['Games_Won'], dtype='object')] 都不在 [index] 中”

At: ax = sb.heatmap(bbt_pd1.transpose().corr().loc[['Games_Won'],:], linewidths=1, linecolor='black', cmap="YlGnBu", annot =True, cbar_kws={'label': '相关系数', 'shrink': 0.6})

这有什么出路吗? TIA

python seaborn heatmap transpose axis
© www.soinside.com 2019 - 2024. All rights reserved.