加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

如何将手动定制的seaborn图添加到JointGrid / jointplot

发布时间:2020-12-20 13:51:09 所属栏目:Python 来源:网络整理
导读:我想使用seaborn JointGrid / jointplot. 在中间我想添加一个sns.regplot.在边缘两个sns.distplots或直方图. 这不是问题,但我想以不同的方式保留所有三个pplot,并为它们三个添加不同的功能和标签. 但我无法解决问题,如果我只使用预定义的方法如何获取图的实
我想使用seaborn JointGrid / jointplot.

在中间我想添加一个sns.regplot.在边缘两个sns.distplots或直方图.

这不是问题,但我想以不同的方式保留所有三个pplot,并为它们三个添加不同的功能和标签.

但我无法解决问题,如果我只使用预定义的方法如何获取图的实例:

g = sns.JointGrid(x="total_bill",y="tip",data=tips)
g = g.plot(sns.regplot,sns.distplot)

手动操纵那些.
或者反过来创建一个regplot和两个distplot实例,我定义了我的方式然后将它们添加到JointGrid,这意味着,但不幸的是,这些以下方法不存在或不起作用那样:

g = sns.JointGrid(x="total_bill",data=tips)
g.add_joint(myreg)           # That would be great but doesn't work
g.ax_marg_x.add(mydist1)     # Just invented code
g.ax_marg_y.add(mydist2)     # Just to show you,the way I'd like to solve the issue

你能给我一个建议吗,如何解决这个问题?

解决方法

那么,documentation has a few examples.如果你想在两个边缘上都有相同的distPlot:

g = sns.JointGrid(x="total_bill",data=tips)
g = g.plot_joint(plt.scatter,color=".5",edgecolor="white")
g = g.plot_marginals(sns.distplot,kde=True,color=".5")

或者如果你想在每个边缘上有不同的情节

g = sns.JointGrid(x="total_bill",data=tips)
g = g.plot_joint(sns.regplot,color="m")
_ = g.ax_marg_x.hist(tips["total_bill"],color="b",alpha=.6,bins=np.arange(0,60,5))
_ = g.ax_marg_y.hist(tips["tip"],color="r",orientation="horizontal",12,1))

然后花了2秒的时间进行实验,以确保您可以将自己的自定义绘图函数传递给marginals和jointPlot,并且必须设置断点以确定哪个参数确定了边缘图的方向

def customJoint(x,y,*args,**kwargs):
    plt.scatter(x,color='red')
def customMarginal(x,**kwargs):
    sns.distplot(x,color='green',vertical=kwargs['vertical'])

g = sns.JointGrid(x="total_bill",data=tips)
g = g.plot(customJoint,customMarginal)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读