plots.py 文件源码

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

项目:nmmn 作者: rsnemmen 项目源码 文件源码
def plotlinfit(xdata,ydata,a,b,erra,errb,cov,linestyle='',conf=0.683,confcolor='gray',xplot=None,front=False,**args):
    """
    This is a wrapper that given the output data from a linear regression
    method (for example, bayeslin.pro, the Bayesian linear regression method 
    of Kelly (2007)), it plots the fits and the confidence bands.
    The input is:
    X, Y, slope (A), errA, intercept (B), errB and cov(A,B)

    Assumes you initialized the plot window before calling this method.

    Usage:

    >>> nemmen.plotlinfit(x,y,a,b,erra,errb,covab,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
    """         
    # Plots best-fit
    if xplot==None:
        x=numpy.linspace(xdata.min(),xdata.max(),100)
    else:
        x=xplot
    pylab.plot(x,a*x+b,linestyle,**args)

    fitm=numpy.array([ a,b ])   # array with best-fit parameters
    covm=numpy.array([ (erra**2,cov), (cov,errb**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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号