Ejemplo n.º 1
0
def scatterplot2D(subplot, figure, dims):
    # set default plot options if necessary
    opts = subplot.opts
    if len(opts) == 0:
        opts['xRange'] = ()
        opts['xRangeAuto'] = True
        opts['yRange'] = ()
        opts['yRangeAuto'] = True 
        opts['xTransform'] = '' 
        opts['yTransform'] = ''
        opts['transformAuto'] = True
        
    
    # Set axes transforms
    if (opts['transformAuto']):
        fcData = DataStore.get(subplot.dataIndex)
        tf = ('xTransform', 'yTransform')
        for i, dim in enumerate(dims):
            t = fcData.getDefaultTransform(dim)
            if (t is not None) and ('log' in t.lower()):
                opts[tf[i]] = 'log'
            else:
                opts[tf[i]] = 'linear'
            
    
    if opts['xRangeAuto']:
        opts['xRange'] = (1, np.max(subplot.Data[:,dims[0]])*1.5)
    if opts['yRangeAuto']:
        opts['yRange'] = (1, np.max(subplot.Data[:,dims[1]])*1.5)
    
    # create the subplot and set its attributes
    subplot.axes = figure.add_subplot(subplot.mnp, xlim=opts['xRange'], 
                                      ylim=opts['yRange'], autoscale_on=False)

    subplot.axes.set_xscale(opts['xTransform'], nonposx='clip')
    subplot.axes.set_yscale(opts['yTransform'], nonposy='clip')
    subplot.axes.set_xlabel(subplot.Labels[dims[0]])
    subplot.axes.set_ylabel(subplot.Labels[dims[1]])
    subplot.axes.set_title(subplot.Title)
    
    # draw the supplied FACS data
    if (not subplot.isDataClustered()):
        subplot.axes.plot(subplot.Data[:,dims[0]], 
                          subplot.Data[:,dims[1]], 
                          '.', ms=1, color='black')
    else:
        data = separate(subplot.Data, subplot.Clustering)
        for i in range(len(data)):
            xs = data[i][:,dims[0]]
            ys = data[i][:,dims[1]]
            subplot.axes.plot(xs, ys, '.', ms=1, color=methods.plotColors[i])
Ejemplo n.º 2
0
def barplot(subplot, figure, dims=None):
    """
    Create a bar chart with one bar for each cluster, and the bar height
    equal to the percent of events contained within the cluster.
    
    Some techniques borrowed from:
    http://www.scipy.org/Cookbook/Matplotlib/BarCharts
    """
    clusters = separate(subplot.Data, subplot.Clustering)
    
    # set default plot options
    opts = subplot.opts
    if len(opts) == 0:
        opts['labelAngle'] = 0 if len(clusters) < 5 else -20
        opts['view'] = 'percent'
    # correcting for previous version
    if 'view' not in opts:
        opts['view'] = 'percent'
    
    dataSize = len(subplot.Data)
    if opts['view'] == 'toplevel':
        dataSize = len(DataStore.getToplevelParent(subplot.dataIndex).data)
    
    if opts['view'] in ['percent', 'toplevel']:
        displayNums = [float(len(cluster))/dataSize*100 for cluster in clusters]
    else:
        displayNums = [len(cluster) for cluster in clusters]
        
    numBars = len(displayNums)
    width = 0.5
    
    xlocs = na.array(range(len(displayNums)))+0.5

    subplot.axes = figure.add_subplot(subplot.mnp, title=subplot.Title, autoscale_on=False)
    subplot.axes.set_xticks(xlocs + width/2)
    if opts['view'] == 'counts':
        subplot.axes.set_xticklabels(map(lambda x: "%i" % x, displayNums), rotation=opts['labelAngle'])
        subplot.axes.set_ylim(0, max(displayNums)*1.2)
    else:
        subplot.axes.set_xticklabels(map(lambda x: "%.2f%%" % x, displayNums), rotation=opts['labelAngle'])
        subplot.axes.set_ylim(0, 100)
        
    subplot.axes.set_xlim(0, xlocs[-1] + width*2)
    subplot.axes.xaxis.tick_bottom()
    subplot.axes.yaxis.tick_left()
    subplot.axes.bar(xlocs, displayNums, width=width, color=methods.plotColors[:numBars])