예제 #1
0
def get_histogram_scale(distances_dict, nbins):
    """Draws histogram to outfile_name.
    """
    scale_dict = defaultdict(list)
    #draw histograms
    for d_dict in distances_dict.values():
        for i, (field, data) in enumerate(d_dict.items()):
            if len(data) < 1:
                continue
            histogram = hist(data, bins=nbins)

            fig = gcf()
            axis = fig.gca()

            #get height scale: y/x
            ymin, ymax = axis.get_ylim()

            xmin, xmax = axis.get_xlim()
            scale_dict['ymin'].append(ymin)
            scale_dict['ymax'].append(ymax)
            scale_dict['xmin'].append(xmin)
            scale_dict['xmax'].append(xmax)

            clf()

    yscale = (min(scale_dict['ymin']), max(scale_dict['ymax']))
    xscale = (min(scale_dict['xmin']), max(scale_dict['xmax']))

    return xscale, yscale
예제 #2
0
def get_histogram_scale(distances_dict, nbins):
    """Draws histogram to outfile_name.
    """
    scale_dict = defaultdict(list)
    #draw histograms
    for d_dict in distances_dict.values():
        for i, (field, data) in enumerate(d_dict.items()):
            if len(data) < 1:
                continue
            histogram = hist(data,bins=nbins)
            
            fig  = gcf()
            axis = fig.gca()

            #get height scale: y/x
            ymin,ymax = axis.get_ylim()
        
            xmin,xmax = axis.get_xlim()
            scale_dict['ymin'].append(ymin)
            scale_dict['ymax'].append(ymax)
            scale_dict['xmin'].append(xmin)
            scale_dict['xmax'].append(xmax)

            clf()
    
    yscale = (min(scale_dict['ymin']),max(scale_dict['ymax']))
    xscale = (min(scale_dict['xmin']),max(scale_dict['xmax']))
    
    return xscale,yscale
예제 #3
0
def draw_histogram(distances, color, nbins, outfile_name,\
    xscale=None, yscale=None, background_color='white',\
    title='', **kwargs):
    """Draws histogram to outfile_name.
    """
    average = mean(distances)
    maximum = max(distances)
    histogram = hist(distances,bins=nbins,facecolor=color, \
        normed=True,**kwargs)

    fig = gcf()
    axis = fig.gca()

    #set labels
    axis.set_xlabel('Distance')
    axis.set_ylabel('Normalized Counts of Pairs in Group')
    axis.set_title(title)
    #get figure scale: width/height
    fig_scale = fig.get_figwidth() / float(fig.get_figheight())

    if xscale is not None:
        axis.set_xlim(xscale)
    if yscale is not None:
        axis.set_ylim(yscale)

    #get height scale: y/x
    ylim = axis.get_ylim()
    ylen = ylim[1] - ylim[0]
    xlim = axis.get_xlim()
    xlen = xlim[1] - xlim[0]
    height_scale = ylen / float(xlen)

    #set width
    width = xlen / 20.
    height = width * height_scale * fig_scale

    #draw circle at average distance
    ellipse = Ellipse([average,0.0],width=width, \
        height=height, \
        edgecolor=color, fill=False)
    axis.add_artist(ellipse)
    #draw line at center of circle
    y1 = -height / 2.
    y2 = height / 2.

    line = Polygon([[average, y1], [average, y2]], edgecolor=color)
    axis.add_artist(line)

    transparent = True
    if background_color != "white":
        axis.set_axis_bgcolor(background_color)
        transparent = False

    savefig(outfile_name, format='png', dpi=72, transparent=transparent)

    close()
    return histogram
예제 #4
0
def draw_histogram(distances, color, nbins, outfile_name,\
    xscale=None, yscale=None, background_color='white',\
    title='', **kwargs):
    """Draws histogram to outfile_name.
    """    
    average = mean(distances)
    maximum = max(distances)
    histogram = hist(distances,bins=nbins,facecolor=color, \
        normed=True,**kwargs)
    
    fig  = gcf()
    axis = fig.gca()
    
    #set labels
    axis.set_xlabel('Distance')
    axis.set_ylabel('Normalized Counts of Pairs in Group')
    axis.set_title(title)
    #get figure scale: width/height
    fig_scale = fig.get_figwidth()/float(fig.get_figheight())
    
    if xscale is not None:
        axis.set_xlim(xscale)
    if yscale is not None:
        axis.set_ylim(yscale)
    
    #get height scale: y/x
    ylim = axis.get_ylim()
    ylen = ylim[1]-ylim[0]
    xlim = axis.get_xlim()
    xlen = xlim[1]-xlim[0]
    height_scale = ylen/float(xlen)
    
    #set width
    width = xlen/20.
    height = width*height_scale*fig_scale
    
    #draw circle at average distance
    ellipse = Ellipse([average,0.0],width=width, \
        height=height, \
        edgecolor=color, fill=False)
    axis.add_artist(ellipse)        
    #draw line at center of circle
    y1 = -height/2.
    y2 = height/2.

    line = Polygon([[average, y1] ,[average, y2]], edgecolor=color)
    axis.add_artist(line)
    
    transparent=True
    if background_color != "white":
        axis.set_axis_bgcolor(background_color)
        transparent=False

    savefig(outfile_name,format='png',dpi=72, transparent=transparent)

    close()
    return histogram