コード例 #1
0
ファイル: objects.py プロジェクト: superking84/tritetris
 def create_random_block(self):
     '''
     Selection is not weighted toward any particular blocks; each block
     has an equal chance of being selected.
     This is an extremely simplistic method nothing like the algorithm
     used in official versions of the game.
     '''
     return Block(self, random.choice(Block._types),\
                  colors.get_random_color())    
コード例 #2
0
ファイル: stacked_bar.py プロジェクト: AsherBond/sirikata
def stacked_bar(title, xlabel, ylabel, indices, labels, widths, vals, errors, group_labels):
    random.seed(0)

    num_bars = len(indices)

    legend_width = 4.5
    fig_height = 10
    fig_width = legend_width + 1 + num_bars

    legend_frac = legend_width / fig_width

    plt.figure(1, figsize=(fig_width, fig_height), dpi=600)
    plt.subplot(1,1,1)
    #plt.subplots_adjust(top=.95, bottom=.179, left=.25, right=1)
    plt.subplots_adjust(top=.95, bottom=.05, left=legend_frac, right=.99)
    sum = [0] * num_bars
    groups = []

    startList=[]
    widthList=[]

    bar_space = 1.0
    bar_offset = 0.05
    bar_width = 0.9
    for x in indices:
        startList.append((x-1)*bar_space+bar_offset);
        widthList.append((x-1)*bar_space+bar_space/2);

    for val,err,width in zip(vals,errors,widths):
        abs_val = [math.fabs(v) for v in val]

        col = colors.get_random_color()
        px = plt.bar(startList, abs_val, bottom=sum, yerr=err, color=col, width=bar_width);
        groups.append(px[0])
        sum = [pre_sum+x for pre_sum,x in zip(sum,abs_val)]

    plt.title(title)
    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    max_sum = max(sum)
    plt.xticks( widthList, labels)
    plt.ylim( (0, max_sum*1.05) )
    plt.xlim( (0, num_bars*bar_space) )

    if (len(groups) > 0):
        groups.reverse()
        group_labels.reverse()
        leg = plt.legend( groups, group_labels, loc=(-legend_width/(1+num_bars), 0) )
        fonts.set_legend_fontsize(leg, 10)

    return plt;
コード例 #3
0
ファイル: main.py プロジェクト: quasiyoke/tornado-chat
 def get(self):
     self.write(template_loader.load('main.html').generate(color=colors.get_random_color()))