import numpy import os import matplotlib as mpl mpl.use('Agg') import matplotlib.pyplot as plt DUDE_MUV_file=open('DUDE_MUV.out') DUDE_MUV_list = list(DUDE_MUV_file) MUV_DUDE_dict={} def save(path, ext='png', close=True, verbose=True): # Extract the directory and filename from the given path directory = os.path.split(path)[0] filename = "%s.%s" % (os.path.split(path)[1], ext) if directory == '': directory = '.' # If the directory does not exist, create it if not os.path.exists(directory): os.makedirs(directory) # The final path to save to savepath = os.path.join(directory, filename) if verbose: print("Saving figure to '%s'..." % savepath), # Actually save the figure # plt.savefig(savepath) plt.savefig(savepath, dpi=900) # import pylab as pl # pl.figure(figsize=(70, 70)) # This increases resolution # pl.savefig('test.eps', format='eps', dpi=900) # This does, too # pl.annotate(..., fontsize='xx-small', ...) # Close it if close: plt.close() if verbose: print("Done") for line in DUDE_MUV_list: ele=line.split() MUV=ele[0] DUDE=ele[1] score = -1*float(ele[-1]) if MUV not in MUV_DUDE_dict.keys(): MUV_DUDE_dict[MUV]=[] MUV_DUDE_dict[MUV].append((DUDE,score)) for MUV in MUV_DUDE_dict.keys(): DUDE_order=[] score_order=[] MUV_DUDE = MUV_DUDE_dict[MUV] for entry in MUV_DUDE: (DUDE,score)=entry DUDE_order.append(DUDE) score_order.append(score) score_order=numpy.array(score_order) fig = plt.figure() ax = fig.add_subplot(311) barlist=plt.bar(range(len(score_order)), score_order, align='edge', width=0.9, alpha=0.5) true_idx = numpy.where(score_order>4)[0] print (true_idx) for d in true_idx: barlist[d].set_color('r') plt.xticks(range(len(score_order)), DUDE_order,rotation='vertical',fontsize = 5) save('../MUV_DUDE_figs/'+MUV+"_DUDE_scores", ext="png", close=True, verbose=True)