gpt4 book ai didi

python - 使用 seaborn jointplot 更改每个点的颜色和标记

转载 作者:太空狗 更新时间:2023-10-29 17:36:51 32 4
gpt4 key购买 nike

我将此代码从 here 稍作修改:

import seaborn as sns
sns.set(style="darkgrid")

tips = sns.load_dataset("tips")
color = sns.color_palette()[5]
g = sns.jointplot("total_bill", "tip", data=tips, kind="reg", stat_func=None,
xlim=(0, 60), ylim=(0, 12), color='k', size=7)

g.set_axis_labels('total bill', 'tip', fontsize=16)

我得到了一个漂亮的图 - 但是,对于我的情况,我需要能够更改每个点的颜色和格式。

我已经尝试使用关键字 markerstylefmt,但出现错误 TypeError: jointplot () 得到了一个意外的关键字参数

正确的做法是什么?我想避免调用 sns.JointGrid 并手动绘制数据和边际分布..

最佳答案

解决这个问题与 matplotlib(绘制具有不同标记和颜色的散点图)几乎没有什么不同,除了我想保持边缘分布:

import seaborn as sns
from itertools import product
sns.set(style="darkgrid")

tips = sns.load_dataset("tips")
color = sns.color_palette()[5]
g = sns.jointplot("total_bill", "tip", data=tips, kind="reg", stat_func=None,
xlim=(0, 60), ylim=(0, 12), color='k', size=7)

#Clear the axes containing the scatter plot
g.ax_joint.cla()

#Generate some colors and markers
colors = np.random.random((len(tips),3))
markers = ['x','o','v','^','<']*100

#Plot each individual point separately
for i,row in enumerate(tips.values):
g.ax_joint.plot(row[0], row[1], color=colors[i], marker=markers[i])

g.set_axis_labels('total bill', 'tip', fontsize=16)

这给了我这个:

enter image description here

回归线现在消失了,但这就是我所需要的。

关于python - 使用 seaborn jointplot 更改每个点的颜色和标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27005783/

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