def _prettyplot(df, prep, prepi, out_file, title=None, size=None): """Plot using prettyplot wrapper around matplotlib. """ cats = ["concordant", "discordant-missing-total", "discordant-extra-total", "discordant-shared-total"] vtypes = df["variant.type"].unique() fig, axs = ppl.subplots(len(vtypes), len(cats)) callers = sorted(df["caller"].unique()) width = 0.8 for i, vtype in enumerate(vtypes): ax_row = axs[i] if len(vtypes) > 1 else axs for j, cat in enumerate(cats): ax = ax_row[j] if i == 0: ax.set_title(cat_labels[cat], size=14) ax.get_yaxis().set_ticks([]) if j == 0: ax.set_ylabel(vtype_labels[vtype], size=14) vals, labels, maxval = _get_chart_info(df, vtype, cat, prep, callers) ppl.bar(ax, np.arange(len(callers)), vals, color=ppl.colors.set2[prepi], width=width) ax.set_ylim(0, maxval) if i == len(vtypes) - 1: ax.set_xticks(np.arange(len(callers)) + width / 2.0) ax.set_xticklabels( [caller_labels.get(x, x).replace("__", "\n") if x else "" for x in callers], size=8, rotation=45 ) else: ax.get_xaxis().set_ticks([]) _annotate(ax, labels, vals, np.arange(len(callers)), width) fig.text(0.5, 0.95, prep_labels.get(prep, "") if title is None else title, horizontalalignment="center", size=16) fig.subplots_adjust(left=0.05, right=0.95, top=0.87, bottom=0.15, wspace=0.1, hspace=0.1) # fig.tight_layout() x, y = (10, 5) if size is None else size fig.set_size_inches(x, y) fig.savefig(out_file)
def cover_freq(tile, cover=None, out=''): flnm = tile + '_cover_freq.npy' if os.path.isfile(flnm): return np.load(flnm) if cover is None: cover = cover_read(tile) his = np.bincount(cover.flat) freq = np.argsort(his)[::-1] mpl.use('PDF') import matplotlib.pyplot as plt, prettyplotlib as ppl #plt.figure(figsize=(11, 6), dpi=300) fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(11, 6)) ppl.bar(ax, range(len(his)), his, width = 1) plt.xticks(range(len(his)), sorted(veg_dict , key=veg_dict.get), rotation=30, fontsize=14) plt.ylabel('Pixel Number', fontsize=14) plt.ticklabel_format(style='sci', axis='y', scilimits=(0,0)) plt.title('Vegetation Type ' + ' @' + tileCord(tile), fontsize=16) plt.tight_layout() plt.savefig(out+tile+'_cover_freq.pdf', dpi=300) plt.close() np.save(flnm,freq) return freq
def timestep(self, data): if isinstance(data, dict) == False: data = json.loads(data) timestamp = float(data["data"]["stat"]["time"]) #if (self.app.tab.currentIndex()==2 ): if (2 == 2): self.figure.clf() ax = self.figure.add_subplot(111) self.figure.set_frameon(False) ax.patch.set_alpha(0) ax.set_xlabel("Time [s]") ax.set_ylabel("Image Count") histdata = self.histdata - np.ceil(timestamp) histdata = histdata[histdata > -100] x = np.linspace(-100, 0, 101) try: hist, edges = np.histogram(histdata, x) ppl.bar(ax, np.linspace(-100, 0, 100), hist) maximum = int(np.max(hist)) except: maximum = 1 ax.set_xlim((-100, 0)) ax.set_ylim((0, 1.2 * maximum)) if size(self.histdata) > 100: speed = -100. / (self.histdata[size(self.histdata) - 101] - self.histdata[size(self.histdata) - 1]) else: speed = 0 ax.set_title( str(data["data"]["stat"]['images processed']) + " frames processed @ approx. " + str(int(speed)) + "fps") self.figure.tight_layout() self.canvas.draw()
def plot_contributors(contributors, outputfile=None): number_of_commits = [] contributor_anonymous = [] count = 1 for contributor in contributors: contributor_commits = contributor.split()[0] number_of_commits.append(int(contributor_commits)) contributor_anonymous.append(count) count = count + 1 fig = plt.figure() ax = fig.add_subplot(111) max_number_of_commits = np.max(number_of_commits) contributors = range(0, max_number_of_commits - 1) prettyplotlib.bar(ax, contributor_anonymous, number_of_commits, width=0.9, grid='y') ax.set_xlabel('ITK Contributors') ax.set_ylabel('Number of Commits') ax.set_xlim(0, 100) if outputfile: fig.savefig(outputfile) else: plt.show()
def makebarplot(series,rejected,title="",filename='_'): rej = rejected == 1 app = rejected == 0 nrej = sum(rej)*1.0 napp = sum(app)*1.0 ser_rej = series[rej] ser_app = series[app] ser_rej_T = sum(ser_rej==True) #ser_rej_F = sum(ser_rej==False) ser_app_T = sum(ser_app==True) #ser_app_F = sum(ser_app==False) ser_rej_plot = [ser_rej_T/nrej] ser_app_plot = [ser_app_T/napp] #ser_plot = [ser_rej_T,ser_app_T] #width = 0.35 ind = np.arange(2) fig, ax = plt.subplots() ppl.bar(ax,ind, np.array([ser_rej_plot,ser_app_plot]), xticklabels=('rejected('+str(ser_rej_T)+')','approved('+str(ser_app_T)+')'), annotate=False) #ax.set_xticks(ind+width) #ax.set_xticks((width/2.0,width*3/2.0)) #ax.set_xticklabels(('rejected('+str(ser_rej_T)+')','approved('+str(ser_app_T)+')')) plt.title(title) plt.ylabel('% of subset rejected/approved') #plt.legend(loc="lower right") filepath = dl.getDataFilePath('plots/fig_'+filename+'.png') plt.savefig(filepath) plt.show()
def plot_kvalues_barchart_dual(l1, l2, xlabel, ylabel, labels, filename, ax= None, loc = 4): ''' Plotting the likelihoods given two dictionaries barchart ''' ind = np.arange(len(l1)) width = 0.35 if ax == None: fig = plt.figure() ax = fig.add_subplot(111) rects1 = ppl.bar(ax, ind, l1.values(), width, color='b') rects2 = ppl.bar(ax, ind+width, l2.values(), width, color='g') #plt.bar(l1.keys(), l1.values(), label=labels[0]) #plt.bar(l2.keys(), l2.values(), label=labels[1]) #ticks = np.arange(min(l1.keys()), max(l1.keys())+1) #print ticks ax.set_xticks(ind+width) ax.set_xticklabels( tuple([str(x) for x in l1.keys()]) ) ax.legend( (rects1[0], rects2[0]), tuple([str(x) for x in labels]), loc = loc ) ax.set_xlabel(xlabel) ax.set_ylabel(ylabel) #plt.legend(loc=4) #plt.show() plt.savefig(filename)
def _prettyplot(df, prep, prepi, out_file, title=None, size=None): """Plot using prettyplot wrapper around matplotlib. """ cats = ["concordant", "discordant-missing-total", "discordant-extra-total", "discordant-shared-total"] vtypes = df["variant.type"].unique() fig, axs = ppl.subplots(len(vtypes), len(cats)) callers = sorted(df["caller"].unique()) width = 0.8 for i, vtype in enumerate(vtypes): ax_row = axs[i] if len(vtypes) > 1 else axs for j, cat in enumerate(cats): ax = ax_row[j] if i == 0: ax.set_title(cat_labels[cat], size=14) ax.get_yaxis().set_ticks([]) if j == 0: ax.set_ylabel(vtype_labels[vtype], size=14) vals, labels, maxval = _get_chart_info(df, vtype, cat, prep, callers) ppl.bar(ax, np.arange(len(callers)), vals, color=ppl.colors.set2[prepi], width=width) ax.set_ylim(0, maxval) if i == len(vtypes) - 1: ax.set_xticks(np.arange(len(callers)) + width / 2.0) ax.set_xticklabels([caller_labels.get(x, x).replace("__", "\n") if x else "" for x in callers], size=8, rotation=45) else: ax.get_xaxis().set_ticks([]) _annotate(ax, labels, vals, np.arange(len(callers)), width) fig.text(.5, .95, prep_labels.get(prep, "") if title is None else title, horizontalalignment='center', size=16) fig.subplots_adjust(left=0.05, right=0.95, top=0.87, bottom=0.15, wspace=0.1, hspace=0.1) #fig.tight_layout() x, y = (10, 5) if size is None else size fig.set_size_inches(x, y) fig.savefig(out_file)
def plot_submissions(data, outputfile=None): fig, ax = plt.subplots(1) prettyplotlib.bar(ax, [y - 0.4 for y in data['year']], data['submissions'], label='Submissions', width=0.4, color=set2[2], grid='y') prettyplotlib.bar(ax, data['year'], data['reviews'], label='Reviews', width=0.4, color=set2[3], grid='y') ax.set_xticks(data['year']) ax.set_xticklabels([str(y) for y in data['year']]) ax.set_xlabel('Year') ax.set_xlim(data['year'][0] - 1, data['year'][-1] + 1) plt.legend(loc='upper left') if outputfile: fig.savefig(outputfile) else: plt.show()
def fig(): fig, ax = plt.subplots(1) ppl.bar(ax, np.arange(10), np.abs(np.random.randn(10))) canvas = FigureCanvas(fig) img = BytesIO() fig.savefig(img) img.seek(0) return send_file(img, mimetype='image/png')
def plot_figure(title, title_of_file): fig, ax = plt.subplots(1) ax.set_title(title) ppl.bar(bin_edges[:-1], hist, width = 1, xticklabels = histogram_bin, annotate = True) fig.savefig(title_of_file)
def plot_helper(li, ti, p): fig, ax = plt.subplots(1) if li % 2: title = "biases" + ti ppl.bar(ax, numpy.arange(p.shape[0]), p) else: title = "weights" + ti ppl.pcolormesh(fig, ax, p) plt.title(title) plt.savefig(title + ".png") #ppl.show() plt.close()
def dataset_touch(): fig, ax = plt.subplots(1) data = read_csv(['dataset_touch'], False) ppl.bar(ax, range(len(data['dataset_touch'])), data['count'], xticklabels=data['dataset_touch'], grid='y', log=True) plt.xlabel('Dataset touch') plt.ylabel('# of queries') plt.show() fig.savefig('plot_datasettouch_sqlshare.pdf', format='pdf', transparent=True) fig.savefig('plot_datasettouch_sqlshare.png', format='png', transparent=True)
def plot_coef(coef_list,err_list,coef_name_list,coef_site_list,title="",cmap=ppl.set2): fig, ax = subplots(1,1) N = len(coef_list[0]) M = len(coef_list) width = 1./(N+1) ax.set_xlim(0,M+1) for i in range(M): X = np.arange(N)+i*width ppl.bar(ax,X,coef_list[i],yerr = err_list[i],label=coef_site_list[i],width=width,color=cmap[i]) ax.set_xticks(np.arange(N)+width*N/2.) ax.set_xticklabels(coef_name_list) ppl.legend(ax)
def vis_time_bars(ven_vs_split, ven_name, fout=None): """ Displays a bar chart representing Hellinger distances between venue and temporal subsets. :param ven_vs_split: array of hellinger distances between venue and its splits :type ven_vs_split: numpy.ndarray :param ven_name: name of venue :type ven_name: str :param fout: save graph to file :type fout: str :return: None :rtype: None """ # TODO: make more flexible to take in all sorts of temporal slices, not just weekdays. xtlabels = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] # x-axis values x = range(7) # y-axis values y = ven_vs_split[1:] # create graph fig, ax = plt.subplots(1) ppl.bar(ax, x, y, xticklabels=xtlabels, facecolor='lightslategrey') ax.yaxis.grid(True, linestyle='-', linewidth=1.5, c='white', zorder=3) # graph settings fig.patch.set_facecolor('white') plt.ylim(0, 1) plt.ylabel("Hellinger Distance", fontsize=16) # spines, axes, ticks ax.spines['bottom'].set_visible(False) ax.spines['left'].set_color('darkslategrey') ax.spines['left'].set_zorder(4) ax.xaxis.label.set_color('darkslategrey') ax.yaxis.label.set_color('darkslategrey') ax.tick_params(axis='y', colors='darkslategrey', labelsize=14) ax.tick_params(axis='x', colors='darkslategrey', labelsize=14) ax.set_frame_on(True) fig.tight_layout() # add venue name, mean, and sd ax.text(6.75, 0.92, ven_name, fontsize=24, ha='right', va='center') mean_sd = 'mean distance = {:1.4f}\nSD = {:1.4f}'.format(np.mean(y), np.std(y)) ax.text(6.75, 0.82, mean_sd, ha='right', va='center', fontsize=16) if fout is None: plt.show() else: fig.savefig(fout)
def fire_freq(tile, veg_ty = 'savanna', fire = None, sea_s = 0, out=''): sea_s = np.min([sea_s,annuN-1]) flnm = tile+veg_ty+'_fire_freq.npy' if os.path.isfile(flnm): fire_freq = np.load(flnm) seaso = fire_freq[sea_s] return seaso if fire is None: fire = fire_read(tile) veg_num = veg_dict[veg_ty] cover = cover_read(tile) cover_m = cover == veg_num cover_freq(tile, cover=cover) del cover fireMa = fire&np.tile(cover_m.reshape(2400,2400,1), (1,1,np.size(fire,2))) freq = np.sum(fireMa[...,annuN:].reshape((2400, 2400, -1, annuN)), axis=2) freq_t = freq.sum(axis=1).sum(axis=0).flatten()#*1.0/np.sum(cover_m)/(endY-startY) if not freq_t.any(): print 'Sample size too small.' print 'Number of fire events on', veg_ty, ':', fireMa.sum() return -1 del freq mpl.use('PDF') import matplotlib.pyplot as plt, prettyplotlib as ppl x_a = [] for dp in daterange16(startY, startY+1): x_a = np.append(x_a, (dp-datetime.timedelta(days=8)).toordinal()) xt = [] for m in range(1, 13): xt = np.append(xt, datetime.date(startY, m, 1).toordinal()) plt.figure(figsize=(11, 6), dpi=300) ppl.bar(x_a, freq_t, width = 16) plt.xticks(xt, ('Jan', '', 'Mar', '', 'May', '', 'Jul', '', 'Sep', '', 'Nov', '')) plt.ticklabel_format(style='sci', axis='y', scilimits=(0,0)) plt.ylabel('Burning Frequency') plt.suptitle('Fire Seasonality of ' + veg_ty + ' @' + tileCord(tile), fontsize=16) plt.savefig(out+tile + veg_ty + 'fire_freq' + '.pdf', dpi=300) plt.close() fire_freq = freq_t.argsort()[::-1] seaso = fire_freq[sea_s] np.save(flnm, fire_freq) return seaso
def plot_helper(li, ti, p): if ppl == None: print >> sys.stderr, "cannot plot this without prettyplotlib" return fig, ax = plt.subplots(1) if li % 2: title = "biases" + ti ppl.bar(ax, numpy.arange(p.shape[0]), p) # TODO with plt else: title = "weights" + ti ppl.pcolormesh(fig, ax, p) # TODO with plt plt.title(title) plt.savefig(title + ".png") #ppl.show() plt.close()
def plot_cpu_load(name): # setup parameters plt.rcParams.update(plot_params) # data to use runs = ['random_1', 'random_2'] algos = ['ml', 'mcl'] algo_params = { 'ml': [18, 36, 54, 72], 'mcl': ['50k', '100k', '200k', '400k'] } # create plot fig, ax = plt.subplots(figsize=(3.4, 1.8)) ax.set_ylim(0, 12) # one bar for each algo,param couple all_durations = [] all_labels = [] all_colors = [] for algo in algos: params = algo_params[algo] for i, param in enumerate(params): # average on runs durations = np.array([]) for run in runs: result_file = '{}_{}_{}'.format(run, algo, param) data = np.loadtxt(os.path.join(result_base_dir, result_file)) durations = np.append(durations, np.average(data[:, 1])) average_durations = np.average(durations) all_durations.append(average_durations) all_labels.append(str(param)) all_colors.append(colors[i]) print algo, param, average_durations ppl.bar(ax, np.arange(len(all_durations)), all_durations, color=all_colors) plt.ylabel('step duration [s]') ax.set_xticks(np.arange(len(all_durations)) + 0.4) ax.set_xticklabels(all_labels) ax.text(2 - 0.1, -2.3, 'Markov Localization', horizontalalignment='center') ax.text(6 - 0.1, -2.3, 'Monte Carlo Localization', horizontalalignment='center') # save figure fig.tight_layout(pad=0.02, rect=(0, 0.08, 1, 1)) fig.savefig(os.path.join(dest_base_dir, name), pad_inches=0.02)
def method_bar(median, yerr, xlabels, **kwargs): colors = kwargs.pop('colors', default_color) legend = kwargs.pop('legend', None) x_offset = kwargs.pop('x_offset', 0.0) label_x_offset = kwargs.pop('label_x_offset', 0.5) rotation = kwargs.pop('rotation', 90) annotatefontsize = kwargs.pop('annotatefontsize', 5) xfontsize = kwargs.pop('xfontsize', 6) width = kwargs.pop('width', 0.7) bar = ppl.bar(ax, np.array(range(len(xlabels))) + x_offset, median, width=width, yerr=[yerr[:, 0], yerr[:, 1]], ecolor='0.5', grid='y', capsize=0, color=colors, annotate=True, annotatefmt='%.d', annotatefontsize=annotatefontsize, **kwargs) plt.ylabel('% cases used') ax.set_xticks(np.array(range(len(xlabels))) + label_x_offset) ax.set_xticklabels(xlabels, fontsize=xfontsize, rotation=rotation, va='top', ha='right') if legend: rect = legend.get_frame() rect.set_facecolor(light_grey) rect.set_linewidth(0.0)
def cover_hisPlt(): his = np.bincount(cover[~(cover==17)]) freq = np.argsort(his)[::-1] mpl.use('PDF') import matplotlib.pyplot as plt, prettyplotlib as ppl fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(11, 6)) ppl.bar(ax, range(len(his)), his, width = 1, grid='y') plt.xticks(range(len(his)), sorted(veg_dict , key=veg_dict.get), rotation=30, fontsize=14) plt.ylabel('Pixel Number', fontsize=14) plt.ticklabel_format(style='sci', axis='y', scilimits=(0,0)) plt.title('Histogram of Vegetation Type', fontsize=16) plt.tight_layout() plt.savefig('afr_cover_his.pdf', dpi=300) plt.close()
def plot_prep_methods(df, prep, prepi, in_file): """Plot comparison between BAM preparation methods. """ out_file = "%s-%s.png" % (os.path.splitext(in_file)[0], prep) cats = ["concordant", "discordant-missing-total", "discordant-extra-total", "discordant-shared-total"] cat_labels = {"concordant": "Concordant", "discordant-missing-total": "Discordant (missing)", "discordant-extra-total": "Discordant (extra)", "discordant-shared-total": "Discordant (shared)"} vtype_labels = {"snp": "SNPs", "indel": "Indels"} prep_labels = {"gatk": "GATK best-practice BAM preparation (recalibration, realignment)", "none": "Minimal BAM preparation (samtools de-duplication only)"} caller_labels = {"ensemble": "Ensemble", "freebayes": "FreeBayes", "gatk": "GATK Unified\nGenotyper", "gatk-haplotype": "GATK Haplotype\nCaller"} vtypes = df["variant.type"].unique() fig, axs = plt.subplots(len(vtypes), len(cats)) callers = sorted(df["caller"].unique()) width = 0.8 for i, vtype in enumerate(vtypes): for j, cat in enumerate(cats): ax = axs[i][j] if i == 0: ax.set_title(cat_labels[cat], size=14) ax.get_yaxis().set_ticks([]) if j == 0: ax.set_ylabel(vtype_labels[vtype], size=14) vals, labels, maxval = _get_chart_info(df, vtype, cat, prep, callers) ppl.bar(ax, left=np.arange(len(callers)), color=ppl.set2[prepi], width=width, height=vals) ax.set_ylim(0, maxval) if i == len(vtypes) - 1: ax.set_xticks(np.arange(len(callers)) + width / 2.0) ax.set_xticklabels([caller_labels[x] for x in callers], size=8, rotation=45) else: ax.get_xaxis().set_ticks([]) _annotate(ax, labels, vals, np.arange(len(callers)), width) fig.text(.5, .95, prep_labels[prep], horizontalalignment='center', size=16) fig.subplots_adjust(left=0.05, right=0.95, top=0.87, bottom=0.15, wspace=0.1, hspace=0.1) #fig.tight_layout() fig.set_size_inches(10, 5) fig.savefig(out_file) return out_file
def cover_hisPlt(): his = np.bincount(cover[~(cover == 17)]) freq = np.argsort(his)[::-1] mpl.use('PDF') import matplotlib.pyplot as plt, prettyplotlib as ppl fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(11, 6)) ppl.bar(ax, range(len(his)), his, width=1, grid='y') plt.xticks(range(len(his)), sorted(veg_dict, key=veg_dict.get), rotation=30, fontsize=14) plt.ylabel('Pixel Number', fontsize=14) plt.ticklabel_format(style='sci', axis='y', scilimits=(0, 0)) plt.title('Histogram of Vegetation Type', fontsize=16) plt.tight_layout() plt.savefig('afr_cover_his.pdf', dpi=300) plt.close()
def compare_weeks(): users = User.objects.filter(is_active=True) today = datetime.date.today() start_of_week = today - datetime.timedelta(days=today.weekday()) start_of_week = datetime.datetime.combine(start_of_week, datetime.time()) last_week = start_of_week - datetime.timedelta(days=7) # Calculate this week's average rating for each Opinion Space # Statement avg_this_week = [] for i in range(1, 6): filtered = UserRating.objects.filter(user__in=users, created__gte=start_of_week, created__lt=start_of_week + datetime.timedelta(days=7), opinion_space_statement__statement_number=i) avg = filtered.aggregate(avg=Avg('rating'))['avg'] if not avg: avg = 0.0 avg_this_week.append(avg) # Calculate last week's average rating for each Opinion Space # Statement avg_last_week = [] for i in range(1, 6): filtered = UserRating.objects.filter(user__in=users, created__gte=last_week, created__lt=start_of_week, opinion_space_statement__statement_number=i) avg = filtered.aggregate(avg=Avg('rating'))['avg'] if not avg: avg = 0.0 avg_last_week.append(avg) labels = ['1', '2', '3', '4', '5'] fig, ax = plt.subplots() ind = np.arange(5) ppl.bar(ax, ind, avg_last_week, width=0.3, annotate=True, xticklabels=labels, color='r', label='Last week') ppl.bar(ax, ind+0.4, avg_this_week, width=0.3, annotate=True, xticklabels=labels, color='b', label='This week') plt.ylim(0.0, 1.1) ax.set_xlabel('QAT Number') ax.set_ylabel('Mean Rating') ppl.legend(ax, loc="upper right") fig.savefig('../../client/media/images/qat.png')
def main(): file_path = '/users/ritali/desktop/ds1004/label_data' dat = pd.read_table(file_path, sep = '\t', header = None) dat.columns = ['key', 'tips', 'long', 'lat', 'boro'] count_man = dat[dat.boro == 'Manhattan'].shape[0] count_bronx = dat[dat.boro == 'Bronx'].shape[0] count_queens = dat[dat.boro == 'Queens'].shape[0] count_staten = dat[dat.boro == 'Staten Island'].shape[0] count_brooklyn = dat[dat.boro == 'Brooklyn'].shape[0] count = [count_man, count_bronx, count_queens, count_staten, count_brooklyn] label = ['Manhattan', 'Bronx', 'Queens', 'Staten Island', 'Brooklyn'] fig, ax = plt.subplots(1) ppl.bar(ax, np.arange(5), count, annotate = True, grid = 'y', xticklabels = label) plt.title('Trip Count for Each Borough') plt.ylabel('Trip Count') plt.xlabel('Borough') fig.savefig('trip_count.pdf')
def plot_contributors(contributors, outputfile=None): number_of_commits = [] contributor_anonymous = [] count = 1 for contributor in contributors: contributor_commits = contributor.split()[0] number_of_commits.append(int(contributor_commits)) contributor_anonymous.append(count) count = count+1 fig = plt.figure() ax = fig.add_subplot(111) max_number_of_commits=np.max(number_of_commits) contributors = range(0,max_number_of_commits-1) prettyplotlib.bar(ax, contributor_anonymous, number_of_commits, width=0.9, grid='y') ax.set_xlabel('ITK Contributors') ax.set_ylabel('Number of Commits') ax.set_xlim(0, 100) if outputfile: fig.savefig(outputfile) else: plt.show()
def bar_chart(self, title, labels, data1, file_name, data2 = None, legend=["", ""]): colors = ["orange", "grey"] data1 = self.__convert_none_to_zero(data1) data2 = self.__convert_none_to_zero(data2) fig, ax = plt.subplots(1) xpos = np.arange(len(data1)) width = 0.35 plt.title(title) y_pos = np.arange(len(data1)) if data2 is not None: ppl.bar(xpos+width, data1, color="orange", width=0.35, annotate=True) ppl.bar(xpos, data2, grid='y', width = 0.35, annotate=True) plt.xticks(xpos+width, labels) plt.legend(legend, loc=2) else: ppl.bar(xpos, data1, grid='y', annotate=True) plt.xticks(xpos+width, labels) plt.savefig(file_name) plt.close()
def plot_coef_split(coef_list,err_list,coef_name_list,coef_site_list,title="",cmap=ppl.set2): N = len(coef_list) # num sites M = len(coef_list[0]) # num coefs fig, ax = subplots(1,M,figsize=(3*M,4)) #One plot per coef width = 1./(N) for j in range(M): #for each coef a = ax[j] a.set_xlim(.2,1.2) for i in range(N): #for each site X = [i*width] #there is one coef ppl.bar(a,X,[coef_list[i][j]], yerr = [err_list[i][j]], label=coef_site_list[i], width=width,color=cmap[i],annotate=True) a.set_xticks([]) a.set_xticklabels([]) a.set_title(coef_name_list[j]) ppl.legend(a)
def hero_stats_bar(self, thresh): ''' Creates a bar chart of the heroes with highest Wins / #Games played ratio ''' # Create individual hero wins and losses self.hero_stats() fig, ax = plt.subplots(1, figsize=(9, 7)) # Compute the ratio of #Wins to the #Games played by that hero # Most relevant statistic, better than W/L Ratio, better than # just wins, all of them can be statistically insignificant # in edge cases, but this can be the least of all val = [ (k, self.wstat[k] / float(self.dstat[k] + self.wstat[k])) for k in self.wstat if self.wstat[k] / float(self.dstat[k] + self.wstat[k]) >= thresh ] plt.title('Hero ID vs. Win Ratio (Matches from 01/23 - 02/24)') plt.xlabel('Hero ID') plt.ylabel('Win Ratio') ax.set_xlim([0, len(val)]) ann = [round(k[1], 2) for k in val] # Extract the xticklabels xtl = [k[0] for k in val] # Extract the individual values to be plotted val = [k[1] for k in val] ppl.bar(ax, np.arange(len(val)), val, annotate=ann, xticklabels=xtl, grid='y', color=ppl.colors.set2[2]) fig.savefig('../Figures/HIDvs#Wins#Games.png') plt.show() plt.clf()
def generate_resource_figure(test, settings, data): file = settings['file'] algos = settings['algos'] resources, format = process_resource_data(settings, data) resources = resources[file] # flatten data flattened = [confidence_interval(resources[algo], config.RESOURCE_ALPHA) for algo in algos] x = np.arange(len(algos)) y = [z[0] for z in flattened] yerr = [z[1] for z in flattened] xticks = list(map(config.ALGO_ABBREVIATIONS.get, algos)) colors = ppl.brewer2mpl.get_map('Set2', 'qualitative', len(algos)).mpl_colors if settings['style']: plot.set_style(settings['style']) plot.new_figure() fig, ax = plt.subplots() rects = ppl.bar(x, y, xticklabels=xticks, yerr=yerr, log=True, grid='y', color=colors) # Annotate for rect in rects: bar_x = rect.get_x() + rect.get_width()/2. bar_y = rect.get_height() label = format(bar_y) plt.annotate(label, xy=(bar_x, bar_y), xytext=(0, 10), textcoords='offset points', horizontalalignment='center', verticalalignment='bottom') plt.xlabel('Compressor') if settings['col'] == 'runtime': plt.ylabel(r'Runtime (\si{\second})') elif settings['col'] == 'memory': plt.ylabel(r'Memory (\si{\byte})') ax.set_yscale('log', basey=2) # units are in powers of two, so scale should be as well # hack to make labels fit ymin, ymax = plt.ylim() plt.ylim((ymin, ymax*2)) plot.save_figure(fig, 'resources', [test])
def method_bar(median,yerr,xlabels, **kwargs): colors=kwargs.pop('colors',default_color) legend=kwargs.pop('legend',None) x_offset=kwargs.pop('x_offset',0.0) label_x_offset = kwargs.pop('label_x_offset',0.5) rotation = kwargs.pop('rotation',90) annotatefontsize = kwargs.pop('annotatefontsize',5) xfontsize = kwargs.pop('xfontsize',6) width=kwargs.pop('width',0.7) bar=ppl.bar(ax,np.array(range(len(xlabels)))+x_offset,median,width=width, yerr=[yerr[:,0],yerr[:,1]], ecolor='0.5', grid='y', capsize=0,color=colors, annotate=True,annotatefmt='%.d',annotatefontsize=annotatefontsize, **kwargs ) plt.ylabel('% cases used') ax.set_xticks(np.array(range(len(xlabels)))+label_x_offset) ax.set_xticklabels(xlabels,fontsize=xfontsize,rotation=rotation,va='top',ha='right') if legend: rect = legend.get_frame() rect.set_facecolor(light_grey) rect.set_linewidth(0.0)
def bar_chart(self, title, labels, data1, file_name, data2=None, legend=["", ""]): """ Generate a bar plot with one or two columns in each x position and save it to file_name :param title: title to be used in the chart :param labels: list of labels for the x axis :param data1: values for the first columns :param file_name: name of the file in which to save the chart :param data2: values for the second columns. If None only one column per x position is shown. :param legend: legend to be shown in the chart :return: """ colors = ["orange", "grey"] data1 = self.__convert_none_to_zero(data1) data2 = self.__convert_none_to_zero(data2) fig, ax = plt.subplots(1) xpos = np.arange(len(data1)) width = 0.35 plt.title(title) y_pos = np.arange(len(data1)) if data2 is not None: ppl.bar(xpos + width, data1, color="orange", width=0.35, annotate=True) ppl.bar(xpos, data2, grid='y', width=0.35, annotate=True) plt.xticks(xpos + width, labels) plt.legend(legend, loc=2) else: ppl.bar(xpos, data1, grid='y', annotate=True) plt.xticks(xpos + width, labels) os.makedirs(os.path.dirname(file_name), exist_ok=True) plt.savefig(file_name) plt.close()
def basic_compare(): matplotlib.rcParams['figure.figsize'] = (8, 5) fig1,ax1 = plt.subplots(1) colormap = plt.cm.spectral plt.gca().set_color_cycle([colormap(i) for i in np.linspace(0, 0.99, 11)]) with open('expdata/fig_ots_basic.pkl','rb') as fp: area2s,meanerrs,merrs_ecd10,curves = pkl.load(fp) figs = list() labels = ['TREES', 'CFAN', 'RCPR', 'IFA', 'CFSS', 'SDM', 'LBF', 'TCDCN', 'CCNF', 'GNDPM', 'DRMF'] for bins,cdf in curves: p, = ppl.plot(bins,cdf,lw=2) figs.append(p) s_ids = np.argsort(-area2s) figs = [figs[i] for i in s_ids] labels = [labels[i] for i in s_ids] plt.legend(figs, labels, loc=4, ncol=2) plt.xlabel('Normalised error') ax1.set_title('(a)') plt.ylabel('Proportion of facial landmarks') plt.grid() fig2,ax2 = plt.subplots(1) anno_area2s = [('%1.5f'%a)[0:6] for a in area2s[s_ids]] ppl.bar(ax2, np.arange(len(area2s)), area2s[s_ids], annotate=anno_area2s, grid='y',xticklabels=labels) plt.ylim((0.1,0.16)) plt.xlim((-0.06,11.02)) plt.xticks(rotation=25) ax2.set_title('(b)') ax2.set_ylabel('AUC$_{0.2}$') fig3,ax3 = plt.subplots(1) anno_me = ['%1.2f'%a for a in meanerrs[s_ids]*100] ppl.bar(ax3, np.arange(len(area2s)), meanerrs[s_ids]*100, annotate=anno_me, grid='y',xticklabels=labels) plt.xlim((-0.06,11.02)) plt.xticks(rotation=30) ax3.set_ylabel('Overall normalised mean error (%)') ax3.set_title('(c)') fig4,ax4 = plt.subplots(1) anno_me2 = ['%1.2f'%a for a in merrs_ecd10[s_ids]*100] ppl.bar(ax4, np.arange(len(area2s)), merrs_ecd10[s_ids]*100, annotate=anno_me2, grid='y',xticklabels=labels) plt.xlim((-0.06,11.02)) plt.xticks(rotation=30) ax4.set_ylabel('Overall normalised mean error (%)') ax4.set_title('(d)')
def bar3_chart(title, labels, data1, file_name, data2, data3, legend=["", ""]): colors = ["orange", "grey"] fig, ax = plt.subplots(1) xpos = np.arange(len(data1)) width = 0.28 plt.title(title) y_pos = np.arange(len(data1)) ppl.bar(xpos+width+width, data3, color="orange", width=0.28, annotate=True) ppl.bar(xpos+width, data1, color='grey', width=0.28, annotate=True) ppl.bar(xpos, data2, grid='y', width = 0.28, annotate=True) plt.xticks(xpos+width, labels) plt.legend(legend, loc=2) plt.savefig(file_name + ".eps") plt.close()
def bar_chart(title, labels, data1, file_name, data2=None, legend=["", ""]): colors = ["orange", "grey"] fig, ax = plt.subplots(1) xpos = np.arange(len(data1)) width = 0.35 plt.title(title) y_pos = np.arange(len(data1)) if data2 is not None: ppl.bar(xpos + width, data1, color="orange", width=0.35, annotate=True) ppl.bar(xpos, data2, grid='y', width=0.35, annotate=True) plt.xticks(xpos + width, labels) plt.legend(legend) else: ppl.bar(xpos, data1, grid='y', annotate=True) plt.xticks(xpos + width, labels) plt.savefig(file_name + ".eps") plt.close()
def bar_chart(title, labels, data1, file_name, data2 = None, legend=["", ""]): colors = ["orange", "grey"] fig, ax = plt.subplots(1) xpos = np.arange(len(data1)) width = 0.35 plt.title(title) y_pos = np.arange(len(data1)) if data2 is not None: ppl.bar(xpos+width, data1, color="orange", width=0.35, annotate=True) ppl.bar(xpos, data2, grid='y', width = 0.35, annotate=True) plt.xticks(xpos+width, labels) plt.legend(legend) else: ppl.bar(xpos, data1, grid='y', annotate=True) plt.xticks(xpos+width, labels) plt.savefig(file_name + ".eps") plt.close()
def test_bar_xticklabels(): np.random.seed(14) n = 10 ppl.bar(np.arange(n), np.abs(np.random.randn(n)), xticklabels=UPPERCASE_CHARS[:n])
import prettyplotlib as ppl import numpy as np from prettyplotlib import plt fig, ax = plt.subplots(1) np.random.seed(14) # 'y' for make a grid based on where the major ticks are on the y-axis ppl.bar(ax, np.arange(10), np.abs(np.random.randn(10)), grid='y') # fig.savefig('bar_prettyplotlib_grid.png') plt.show()
"otros socios\n(" + numero_socios[1] + " socios)", ], rotation="horizontal", multialignment="center") ax.autoscale() ax.set_title(u'Ganancias de socios principales y vitalicios\n comparados con el resto de socios', fontdict = {'fontsize':22} ) y_labels = ["0", "1,000,000", "2,000,000", "3,000,000", "4,000,000", "5,000,000", "6,000,000", "7,000,000", "8,000,000"] ax.set_yticklabels(y_labels) plt.ylabel(u'Regalías en S/.', fontdict={'fontsize':18}) plt.xlabel(u'Beneficiarios', fontdict={'fontsize':22}) ppl.bar(ax, np.arange(len(y)), y, grid="y", annotate=annotate, color=bar_color) fig.tight_layout() fig.savefig("output/socios_principales.png") output = "Plot de socios Principales + Vitalicios guardados en archivo " output += "``output/socios_principales.png``\n" print output ## DO principales + vitalicios + activos ## numero de socios por categoria numero_socios = [str(len(principales) + len(vitalicios) + len(activos)), str(250-len(principales) - len(vitalicios) - len(activos))] # Porcentaje de socios principales+vitalicios+activos versus otros percent_pva = float((len(principales)+len(vitalicios)+len(activos))*100/250) percent_socios_otros = 100.0 - percent_pva
def test_bar_xticklabels(): fig, ax = plt.subplots(1) np.random.seed(14) n = 10 ppl.bar(ax, np.arange(n), np.abs(np.random.randn(n)), xticklabels=string.uppercase[:n])
def test_bar_xticklabels(): fig, ax = plt.subplots(1) np.random.seed(14) n = 10 ppl.bar(ax, np.arange(n), np.abs(np.random.randn(n)), xticklabels=UPPERCASE_CHARS[:n])
def show_population_animation_bars(X, idx_x=50, idx_y=50, interval=150, colormap=None, blit=False, kind='cartesian', save=None, show_initial=True, xlabel=u"\u03B8", ylabel=u"Y[\u03B8]", decoding_method='vote', fdomain=DEFAULT_FDOMAIN, frame_id=None, ax=None, show_legend=True, show_title=True): """ Docstring for show_population_animation """ # WARNING: FOR THIS ANIMATION TO WORK, # THE OBJECT ANIM HAS TO BE RETURNED BY # THE CALLING FUNCTION. ################################################################ # setup plot and sampli loci ################################################################ try: import prettyplotlib as ppl plt = ppl.plt plot, legend = ppl.plot, ppl.legend except ImportError: import matplotlib.pyplot as plt plot, legend = plt.plot, plt.legend import matplotlib.animation as animation if kind == 'cartesian': subplot_kw = {'polar': False} elif kind == 'polar': subplot_kw = {'polar': True} else: raise ValueError('Invalid graph type') # Multiple sampling loci are allowed try: [idx for idx in idx_x] except TypeError: idx_x = [idx_x] try: [idx for idx in idx_y] except TypeError: idx_y = [idx_y] try: assert len(idx_x) == len(idx_y) except AssertionError: raise Exception( 'Coordinate lists idx_x and idx_y have different lengths') else: n_curves = len(idx_x) n_timesteps = X.shape[0] n_neurons = X.shape[1] xs = sp.arange(n_neurons) ################################################################ # generate colors for histograms & other graphics parameters ################################################################ if colormap is None: colormap = [plt.cm.gist_rainbow(k) \ for k in sp.linspace(0, 0.9, n_curves)] if show_initial: INITIAL_LINE_WIDTH = 5. else: INITIAL_LINE_WIDTH = 0. if n_curves < 4: ALPHA_BAR_NORMAL = .33 ALPHA_BAR_HIGHLIGHTED = .60 else: ALPHA_BAR_NORMAL = .20 ALPHA_BAR_HIGHLIGHTED = .75 BAR_WIDTH = .75 ################################################################ # create main figure ################################################################ if not ax: fig, ax = plt.subplots(subplot_kw=subplot_kw) else: fig = plt.gcf() # ax.patch.set_facecolor('white') y = sp.array([X[:, :, i_, j_] for i_, j_ in zip(idx_x, idx_y)]) for idx, (i_, j_) in enumerate(zip(idx_x, idx_y)): y[idx, :, :] = X[:, :, i_, j_] ax.set_xlim([0, n_neurons - 1]) ax.set_ylim([0, y.max()]) xticks_val = sp.linspace(fdomain[0], fdomain[1], 21) xticks_pos = sp.linspace(0, n_neurons - 1, 21) + BAR_WIDTH / 2. ax.set_xticks(xticks_pos, minor=False) ax.set_xticklabels(['%1.2f' % i for i in xticks_val], minor=False) plt.show() plt.draw() ################################################################ # define decoder from population to index ################################################################ def decode_index(y_idx_i, kind=decoding_method): """ get population-index of decoded value """ decoded_value_index = int( sp.around(decode(y_idx_i, kind=kind, axis=0) * n_neurons)) # corner case if vote decoding over circular variable decoded_value_index = 0 if decoded_value_index \ == n_neurons else decoded_value_index return decoded_value_index ################################################################ # draw initial population curves at time = 0 ################################################################ grpbars, rline = [], [] for idx, (i_, j_) in enumerate(zip(idx_x, idx_y)): bars = ppl.bar(xs, y[idx][0], ax=ax, width=BAR_WIDTH, color=colormap[idx], alpha=ALPHA_BAR_NORMAL, linewidth=0., edgecolor='k', label='Normalized population response') grpbars.append(bars) grpbars = tuple(grpbars) # set alpha for bar-of-decoded, initial frame for idx in sp.arange(n_curves): decoded_value_index = decode_index(y[idx][0]) for j, b in enumerate(grpbars[idx]): if j == decoded_value_index: b.set_linewidth(0) b.set_alpha(ALPHA_BAR_HIGHLIGHTED) ################################################################ # Draw vertical lines at loci of population curves maxima, or, # in the polar case, radial lines from center to loci of # population curves maxima ################################################################ for idx in range(n_curves): max_y0 = y[idx][0].max() decoded_value_index = decode_index(y[idx][0]) rline_idx = ax.add_line( plt.Line2D(xdata=(decoded_value_index + BAR_WIDTH / 2., decoded_value_index + BAR_WIDTH / 2.), ydata=ax.get_ylim(), color=colormap[idx], linestyle='--', alpha=.50, linewidth=INITIAL_LINE_WIDTH)) rline.append(rline_idx) rline = tuple(rline) ################################################################ # Axes, labels and legends ################################################################ if kind == 'cartesian': ax.set_xlabel(xlabel, labelpad=15., fontweight='bold') ax.set_ylabel(ylabel, fontweight='bold') title_ = ax.set_title('') ax.tick_params(axis='both', which='major') ax.xaxis.set_label_position('bottom') elif kind == 'polar': pass if show_legend: legend_patches = [patches.Patch( color=c, label='Population at [%i, %i]' \ % (i, j)) for i, j, c in zip(idx_x, idx_y, colormap)] legend_lines = [lines.Line2D([0, 0], [0, 0], linewidth=2*INITIAL_LINE_WIDTH, linestyle='--', color=c, label='Initial decoding at [%i, %i]' % (i, j)) \ for i, j, c in zip(idx_x, idx_y, colormap)] legend_elements = legend_patches + legend_lines ax.legend(handles=legend_elements) plt.show() plt.draw() ################################################################ # Animate: this function *must* return one tuple for all changed # objects for animation.FuncAnimation to know what it must # update in the figure ################################################################ def update_plot(i): if show_title: title_.set_text('Iteration: t = %i / %i' % (i + 1, len(X))) fig.canvas.set_window_title('t = %i / %i' % (i + 1, len(X))) if i == -1: return grpbars for idx in sp.arange(n_curves): decoded_value_index = decode_index(y[idx][i]) for j, b in enumerate(grpbars[idx]): b.set_height(y[idx][i][j]) b.set_linewidth(0) b.set_alpha(ALPHA_BAR_NORMAL) if j == decoded_value_index: b.set_linewidth(0) b.set_alpha(ALPHA_BAR_HIGHLIGHTED) plt.show() plt.draw() return grpbars ################################################################ # initialization function ################################################################ def init(): return update_plot(0) ################################################################ # run animation ################################################################ try: return update_plot(frame_id - 1) except AssertionError: raise ValueError('Frame ID should be positive') except TypeError: raw_input("Press Enter to start animation.") anim = animation.FuncAnimation(fig, update_plot, len(X), init_func=init, interval=interval, blit=blit) plt.show() plt.draw() if save: anim.save(save, writer='avconv') return anim
#!/usr/bin/env python2.7 import sys import pdb import argparse import re import pandas as pd import matplotlib.pyplot as plt import prettyplotlib as ppl import numpy as np if __name__ == '__main__': fig, axes = plt.subplots() ppl.bar(axes, [0], [80], label="Redshift", xticklabels=[]) ppl.bar(axes, [0], [40], bottom=[80], color=ppl.colors.set2[1], label="CSV") xlim = axes.get_xlim() xlim_right = 1.5 * xlim[1] newXlim = (xlim[0], xlim_right) axes.set_xlim(newXlim) axes.set_ylabel("time (s)") axes.legend(loc=0, frameon=False) fig.savefig("RedshiftCSV_bar.pdf")
def stackedBarsBlockedEdgesByRoutine(type_header, type_table, config, instanceType, solsPath=None, solsExt=None, useTotalEdges=False, figName=None, routine_map=None): if config not in type_table: raise Exception("Config \"" + config + "\" not found!") if instanceType not in type_table[config]: raise Exception("Instance type \"" + instanceType + "\" not found!") fig, ax = plt.subplots(1) routines = [] rgexs = r'[^.]+\.([^.]+).blockedEdges' routineR = re.compile(rgexs) for h in type_header: routine = routineR.search(h) if routine != None: routines.append(routine.group(1)) data = [] sizes = sorted(type_table[config][instanceType].iterkeys()) for size in sizes: if useTotalEdges: totalVars = np.array( map(int, type_table[config][instanceType][size]['nVarsTotal'])) totalEdges = [size * (size - 1) / 2] * len(totalVars) refNEdges = totalEdges else: solsNEdges = getNEdgesArray(type_table, type_header, config, instanceType, size, solsPath, solsExt) totalEdges = [size * (size - 1) / 2] * len(solsNEdges) refNEdges = totalEdges - solsNEdges for index, routine in enumerate(routines): if index >= len(data): data.append([]) columnName = 'preproc.' + routine + '.blockedEdges' blockedEdges = np.array( map(int, type_table[config][instanceType][size][columnName])) propBlockedEdges = np.array( map(lambda r, t: float(r) / float(t), blockedEdges, refNEdges)) avgPropBlockedEdges = propBlockedEdges.mean() * 100.0 if figName == 'bEdges-exclReg-routines-mdtp.pdf': print size, ": bEdges:", routine, ":", avgPropBlockedEdges data[index].append(avgPropBlockedEdges) # Get "Set2" colors from ColorBrewer (all colorbrewer scales: http://bl.ocks.org/mbostock/5577023) colors = brewer2mpl.get_map('Set2', 'qualitative', max(len(routines), 3)).mpl_colors clean_data = [] clean_routines = [] clean_colors = [] for index, routine in enumerate(routines): if data[index].count(0) != len(data[index]): clean_data.append(data[index]) clean_routines.append(routine) clean_colors.append(colors[index]) data = np.array(clean_data) routines = clean_routines colors = clean_colors if routine_map != None: # labels = np.array( [routine_map[r] for r in routines] ) labels = np.array(map(routine_map.get, routines)) else: labels = np.array(routines) bottom = np.vstack((np.zeros( (data.shape[1], ), dtype=data.dtype), np.cumsum(data, axis=0)[:-1])) width = 0.8 ind = [x - width / 2 for x in range(1, len(data[0]) + 1)] for dat, lab, bot, col in reversed(zip(data, labels, bottom, colors)): ppl.bar(ax, ind, dat, width, grid='y', bottom=bot, label=lab, color=col) ax.set_xlabel(u'# Pontos') ax.set_xticks(range(1, len(sizes) + 1)) ax.set_xticklabels(map(str, sizes)) ax.set_xlim(0.5, len(sizes) + 0.5) ax.set_ylabel(u'% Arestas bloqueadas') ppl.legend(ax, loc="lower right") if figName != None and type(figName) == str: fig.savefig(figName, bbox_inches='tight')
def test_bar_annotate_user(): np.random.seed(14) ppl.bar(np.arange(10), np.abs(np.random.randn(10)), annotate=range(10, 20))
def test_bar_annotate(): np.random.seed(14) ppl.bar(np.arange(10), np.abs(np.random.randn(10)), annotate=True)
def test_bar_grid(): np.random.seed(14) ppl.bar(np.arange(10), np.abs(np.random.randn(10)), grid='y')
def test_bar(): np.random.seed(14) ppl.bar(np.arange(10), np.abs(np.random.randn(10)))
#scalars = opp.getScalars('module("Net10.rte[0].queue[0]")') scalars = opp.getScalars('*') endTime = time.perf_counter() print("getScalars took " + str((endTime - startTime) * 1000.0) + " ms") #print(str(len(scalars))) df = scalars[scalars.type == "scalar"] # pd.DataFrame(scalars) df["value"] = pd.to_numeric(df["value"]) df = df[(df.name == "busy:timeavg") & (df.value > 0)] vals = pd.to_numeric(df["value"]).tolist() names = df["module"].tolist() #print(str(list(zip(names, vals)))) fig, ax = plt.subplots(1) ppl.bar(ax, np.arange(len(vals)), vals) plt.xticks(np.arange(len(vals)), names, rotation='vertical') ax.yaxis.grid() plt.tight_layout() #cursor = Cursor(ax, useblit=False, color='red', linewidth=2 ) plt.show()
def test_bar_grid(): fig, ax = plt.subplots(1) np.random.seed(14) ppl.bar(ax, np.arange(10), np.abs(np.random.randn(10)), grid='y')
def test_bar_annotate_user(): fig, ax = plt.subplots(1) np.random.seed(14) ppl.bar(ax, np.arange(10), np.abs(np.random.randn(10)), annotate=range(10,20))
data = json.load(f) # make a plot for every attribute try: os.mkdir('plots') except OSError: pass cores_list = [int(cores) for cores in data.keys()] cores_list.sort() # get the first dict as a sample so we know what attributes to look for sample = data[list(data)[0]]['total'] for attr in sample.keys(): xs = [] ys = [] for cores in cores_list: cores = str(cores) # for JSON indexing xs.append(int(cores)) ys.append(int(data[cores]['total'][attr])) # convert to GBs ys = [y / (1024.0 * 1024.0) for y in ys] bottom = np.arange(len(cores_list)) fig, ax = plt.subplots() ppl.bar(ax, bottom, ys, annotate=True, xticklabels=xs, grid='y') plt.xlabel('Number of Nodes') plt.ylabel('Aggregated Bandwidth (GB/s)') plt.title('%s' % attr[0].upper() + attr[1:]) fig.savefig('plots/%s.png' % attr) plt.close(fig)