cute_plot.py 文件源码

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

项目:cellcomplex 作者: VirtualPlants 项目源码 文件源码
def box_plot(figure,X,data,colors,xlabel="",ylabel="",box_width=None,linewidth=3,marker_size=20,alpha=1):
    font = fm.FontProperties(family = 'Trebuchet', weight ='light')
    #font = fm.FontProperties(family = 'CenturyGothic',fname = '/Library/Fonts/Microsoft/Century Gothic', weight ='light')
    figure.patch.set_facecolor('white')
    axes = figure.add_subplot(111)

    if box_width is None:
        if len(X)>1:
            box_width = ((np.array(X)[1:] - np.array(X)[:-1]).mean())/3.
        else:
            box_width = 0.33
    for x in xrange(len(X)):
        color = colors[x]
        box_color = np.array(color)/2.

        axes.fill_between([X[x]-box_width,X[x]+box_width],[np.percentile(data[x],75),np.percentile(data[x],75)],[np.percentile(data[x],25),np.percentile(data[x],25)],facecolor=color,alpha=alpha/2.)
        axes.plot([X[x]-box_width,X[x]+box_width],[np.percentile(data[x],50),np.percentile(data[x],50)],color=box_color,linewidth=linewidth,alpha=(alpha+1)/2)
        axes.plot([X[x]-box_width,X[x]+box_width],[np.percentile(data[x],25),np.percentile(data[x],25)],color=box_color,linewidth=linewidth/2.,alpha=alpha)
        axes.plot([X[x]-box_width,X[x]+box_width],[np.percentile(data[x],75),np.percentile(data[x],75)],color=box_color,linewidth=linewidth/2.,alpha=alpha)
        axes.plot([X[x]-box_width,X[x]-box_width],[np.percentile(data[x],25),np.percentile(data[x],75)],color=box_color,linewidth=linewidth/2.,alpha=alpha)
        axes.plot([X[x]+box_width,X[x]+box_width],[np.percentile(data[x],25),np.percentile(data[x],75)],color=box_color,linewidth=linewidth/2.,alpha=alpha)
        axes.plot([X[x],X[x]],[np.percentile(data[x],25),np.percentile(data[x],10)],color=box_color,linewidth=linewidth/3.,alpha=alpha)
        axes.plot([X[x],X[x]],[np.percentile(data[x],75),np.percentile(data[x],90)],color=box_color,linewidth=linewidth/3.,alpha=alpha)
        axes.plot([X[x]-box_width/4.,X[x]+box_width/5.],[np.percentile(data[x],10),np.percentile(data[x],10)],color=box_color,linewidth=linewidth/2.,alpha=alpha)
        axes.plot([X[x]-box_width/4.,X[x]+box_width/5.],[np.percentile(data[x],90),np.percentile(data[x],90)],color=box_color,linewidth=linewidth/2.,alpha=alpha)
        # axes.plot(X[x],np.percentile(data[x],50),'o',markersize=np.pi*np.power(box_width/2.,2.),markeredgewidth=linewidth/2.,color=color)

        outliers = [d for d in data[x] if (d < np.percentile(data[x],10)) or (d > np.percentile(data[x],90))]
        x_outliers = [X[x] for d in outliers]
        axes.scatter(x_outliers, outliers, s=marker_size/3.,c=color,linewidth=0,alpha=alpha/2.)

    axes.set_xlim(min(X)-1,max(X)+1)
    axes.set_xlabel(xlabel,fontproperties=font, size=10, style='italic')
    axes.set_xticklabels(axes.get_xticks(),fontproperties=font, size=12)
    axes.set_ylabel(ylabel, fontproperties=font, size=10, style='italic')
    axes.set_yticklabels(axes.get_yticks(),fontproperties=font, size=12)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号