plots.py 文件源码

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

项目:nmmn 作者: rsnemmen 项目源码 文件源码
def fitconf(xdata,ydata,errx,erry,covxy,nboot=1000,bces='ort',linestyle='',conf=0.683,confcolor='gray',xplot=None,front=False,**args):
    """
    This is a wrapper that given the input data performs the BCES
    fit, get the orthogonal parameters and plot the best-fit line and
    confidence band (generated using analytical methods). 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.fitconf(x[i],y[i],errx[i],erry[i],covxy[i],nboot,bces,linestyle='k',confcolor='LightGrey')

    Explanation of some arguments:

    - xplot: if provided, will compute the confidence band in the X-values provided
    with xplot
    - front: if True, then will plot the confidence band in front of the data
    points; otherwise, will plot it behind the points
    """ 
    # 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]

    # Plots confidence band
    lcb,ucb,xcb=confbandnl(xdata,ydata,func,fitm,covm,2,conf,x)
    if front==True:
        zorder=10
    else:
        zorder=None
    pylab.fill_between(xcb, lcb, ucb, alpha=0.3, facecolor=confcolor, zorder=zorder)

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


问题


面经


文章

微信
公众号

扫码关注公众号