gpt4 book ai didi

python - 六边形联合图的 Seaborn 成对矩阵

转载 作者:太空狗 更新时间:2023-10-30 02:19:14 27 4
gpt4 key购买 nike

我正在尝试生成比较分布 (something like this) 的成对图矩阵。由于我有很多要点,所以我想使用 hexbin 图来减少时间和绘图的复杂性。

import seaborn as sns
import matplotlib.pyplot as plt


tips = sns.load_dataset("tips")

g = sns.FacetGrid(tips, col="time", row="sex")
g.map(sns.jointplot, "total_bill", "tip", kind="hex")
plt.show()

然而,它不是创建绘图矩阵,而是在不同窗口中独立创建多个绘图。

我也想过使用 seaborn.pairplot 来生成这个,但我不能将 "hex" 作为值传递给 kind

最佳答案

请参阅 tutorial on using custom functions 中的最后一个示例使用 FacetGrid,我将在此处重现:

def hexbin(x, y, color, **kwargs):
cmap = sns.light_palette(color, as_cmap=True)
plt.hexbin(x, y, gridsize=15, cmap=cmap, **kwargs)

g = sns.FacetGrid(tips, hue="time", col="time", size=4)
g.map(hexbin, "total_bill", "tip", extent=[0, 50, 0, 10])

enter image description here

关于python - 六边形联合图的 Seaborn 成对矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31385375/

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