plots.py 文件源码

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

项目:nmmn 作者: rsnemmen 项目源码 文件源码
def threehists(x1,x2,x3,xmin,xmax,x1leg='$x_1$',x2leg='$x_2$',x3leg='$x_3$',xlabel='',fig=1,sharey=False,fontsize=12):
    """
Script that plots three histograms of quantities x1, x2 and x3 
sharing the same X-axis.

Arguments:
- x1,x2,x3: arrays with data to be plotted
- xmin,xmax: lower and upper range of plotted values, will be used to set a consistent x-range for both histograms.
- x1leg, x2leg, x3leg: legends for each histogram   
- xlabel: self-explanatory.
- sharey: sharing the Y-axis among the histograms?
- fig: which plot window should I use?

Example:
x1=Lbol(AD), x2=Lbol(JD), x3=Lbol(EHF10)

>>> threehists(x1,x2,x3,38,44,'AD','JD','EHF10','$\log L_{\\rm bol}$ (erg s$^{-1}$)',sharey=True)

Inspired by `Scipy <http://www.scipy.org/Cookbook/Matplotlib/Multiple_Subplots_with_One_Axis_Label>`_.
    """
    pylab.rcParams.update({'font.size': fontsize})
    fig=pylab.figure(fig)
    pylab.clf()

    a=fig.add_subplot(3,1,1)
    if sharey==True:
        b=fig.add_subplot(3,1,2, sharex=a, sharey=a)
        c=fig.add_subplot(3,1,3, sharex=a, sharey=a)
    else:
        b=fig.add_subplot(3,1,2, sharex=a)
        c=fig.add_subplot(3,1,3, sharex=a)      

    a.hist(x1,label=x1leg,color='b',histtype='stepfilled')
    a.legend(loc='best',frameon=False)
    a.set_xlim(xmin,xmax)

    b.hist(x2,label=x2leg,color='r',histtype='stepfilled')
    b.legend(loc='best',frameon=False)

    c.hist(x3,label=x3leg,color='y',histtype='stepfilled')
    c.legend(loc='best',frameon=False)

    pylab.setp(a.get_xticklabels(), visible=False)
    pylab.setp(b.get_xticklabels(), visible=False)

    c.set_xlabel(xlabel)
    b.set_ylabel('Number')
    pylab.minorticks_on()
    pylab.subplots_adjust(hspace=0.15)
    pylab.draw()
    pylab.show()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号