gpt4 book ai didi

python - Seaborn FacetGrid + 热图灰色边框

转载 作者:行者123 更新时间:2023-11-30 22:36:04 26 4
gpt4 key购买 nike

给出以下示例:

A = [0, 1, 2]
B = [3, 4, 5]
C = [6, 7, 8, 9]

df = pd.DataFrame(data = {'D': np.random.randn(3*3*4)},
index = pd.MultiIndex.from_product([A, B, C], names=['A', 'B', 'C']))

df.reset_index(['B', 'C'], inplace=True)

def facet_heatmap(data, color):
data = data.pivot(columns='B', values='D')
ax = sns.heatmap(data, square=True, cmap="coolwarm", linewidths=0.0, rasterized=True, cbar=False)
ax.invert_yaxis()

g = sns.FacetGrid(df, col='C', col_wrap=2)
g.map_dataframe(facet_heatmap)

当使用可选参数 square=True 时,网格的每个子图中都有一些灰色边框。但是,当 square=False (默认值)时,灰色边框消失。有人知道如何在保持 square=True 的同时删除灰色边框吗?

最佳答案

这不是边框,只是灰色背景。您可以使用seaborn的set_style函数将其设置为白色:

sns.set_style("whitegrid")

关于python - Seaborn FacetGrid + 热图灰色边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44332117/

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