plots.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:nmmn 作者: rsnemmen 项目源码 文件源码
def fitconfpred(xdata,ydata,errx,erry,covxy,nboot=1000,bces='ort',linestyle='',conf=0.68,confcolor='LightGrey',predcolor='Khaki',xplot=None,front=False,**args):
    """
    This is a wrapper that given the input data performs the BCES
    fit, get the orthogonal parameters and plot (i) the best-fit line,
    (ii) confidence band and (iii) prediction band. 

    I decided to put together these commands in a method because I have been 
    using them very frequently.

    Assumes you initialized the plot window before calling this method.

    Usage:

    >>> a1,b1,erra1,errb1,cov1=nemmen.fitconfpred(x[i],y[i],errx[i],erry[i],covxy[i],nboot,bces,linestyle='k',confcolor='LightGrey')
    """ 
    # Selects the desired BCES method
    i=whichbces(bces)

    # Performs the BCES fit
    a,b,erra,errb,cov=bcesp(xdata,errx,ydata,erry,covxy,nboot)

    # Plots best-fit
    if xplot==None:
        x=numpy.linspace(xdata.min(),xdata.max(),100)
    else:
        x=xplot
    pylab.plot(x,a[i]*x+b[i],linestyle,**args)

    fitm=numpy.array([ a[i],b[i] ]) # array with best-fit parameters
    covm=numpy.array([ (erra[i]**2,cov[i]), (cov[i],errb[i]**2) ])  # covariance matrix
    def func(x): return x[1]*x[0]+x[2]

    if front==True:
        zorder=10
    else:
        zorder=None

    # Plots prediction band
    lpb,upb,xpb=predbandnl(xdata,ydata,func,fitm,covm,2,conf,x)
    pylab.fill_between(xpb, lpb, upb, facecolor=predcolor,edgecolor='', zorder=zorder)

    # Plots confidence band
    lcb,ucb,xcb=confbandnl(xdata,ydata,func,fitm,covm,2,conf,x)
    pylab.fill_between(xcb, lcb, ucb, facecolor=confcolor,edgecolor='', zorder=zorder)

    return a,b,erra,errb,cov
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号