def plot_ridgline(hat_double_array, title, x_label, par_list, bins=10): """ Plots several histograms in progression one under another, agreed by hirizontal axis. Is based on joypy library. :param hat_double_array: a double array, containg the plotted values. Columns correspond to histograms. :param title: a title for the image to be saved. :param x_label: a label for the common x axis. :param par_list: a dictionary of parameteres and their values that go to the caption. :param bins: a number of bins to be used for histograms. """ file_name, caption = plot_preparations(title=title, par_list=par_list) plt.style.use('seaborn') joypy.joyplot(hat_double_array, hist=True, bins=bins, overlap=0, grid=True, legend=False) plt.xlabel(x_label + '\n' + caption) plt.title(title) plt.tight_layout() plt.savefig(file_name, dpi=300, bbox_inches='tight') plt.close()
def joyplotOverlap(feat, cL, by=None, lab1='via', lab2='tile', ax=None): import joypy if by == None: fig, ax = joypy.joyplot(feat, column=cL, xlim='own', ylim='own', figsize=(12, 6), alpha=.5) else: feat.loc[:, by] = feat.loc[:, by].astype(int) feat = feat.melt(id_vars=[by], value_vars=cL) sorter = dict(zip(cL, range(len(cL)))) feat.loc[:, 'rank'] = feat['variable'].map(sorter) feat = feat.sort_values('rank') fL = np.unique(feat[by]) vL = [] for i in fL: var = by + "_" + str(i) feat.loc[:, by + "_" + var] = float('nan') setL = feat[by] == i feat.loc[setL, var] = feat.loc[setL, "value"] vL.append(var) fig, ax = joypy.joyplot(feat, column=vL, by="rank", xlim='own', ylim='own', figsize=(12, 6), alpha=.5, labels=cL) return fig, ax
def make_joyplot(ns, nb, g): tmp = df.copy() tmp['gene_exp'] = get_exp_gene(g) joypy.joyplot(tmp, by="Channel", ylim='own', column="gene_exp") plt.savefig("test.png", bbox_inches='tight') s2 = base64.b64encode(open("test.png", "rb").read()).decode("utf-8").replace("\n", "") return [html.Img(id="plot", src="data:image/png;base64,%s" % (s2))]
def make_figure_subset(selectedPoints, antibody_selection, g): if selectedPoints == None: return None, None, None # customdata index_list = [x['customdata'][0] for x in selectedPoints['points']] print(len(index_list), index_list[0]) tmp = df.copy() tmp['gene_exp'] = get_exp_gene(g) tmp = tmp.loc[index_list] AB1 = antibody_selection[0] AB2 = antibody_selection[1] tmp[AB1] = antibody_df.loc[AB1] tmp[AB2] = antibody_df.loc[AB2] title = "(Selected) Number of cells<br> %s" % (str( tmp["Channel"].value_counts().to_json()).replace(",", "<br>")) print(title) fig3 = px.scatter( tmp, x=AB1, y=AB2, color='gene_exp', symbol="Channel", hover_data=['barcodekey', 'n_genes', 'n_counts', 'louvain_labels'], opacity=0.5, size_max=3, template="simple_white", title=title) fig3.update_layout(coloraxis_colorbar=dict( yanchor="top", y=0.5, x=1, ticks="outside", len=0.5)) fig4 = px.scatter( tmp, x="UMAP1", y="UMAP2", color='gene_exp', symbol="Channel", hover_data=['barcodekey', 'n_genes', 'n_counts', 'louvain_labels'], opacity=0.5, size_max=3, template="simple_white", title=title) fig4.update_layout(coloraxis_colorbar=dict( yanchor="top", y=0.5, x=1, ticks="outside", len=0.5)) # print (fig3) # print (fig4) joypy.joyplot(tmp, by="Channel", ylim='own', column="gene_exp") plt.savefig("test2.png", bbox_inches='tight') s2 = base64.b64encode(open("test2.png", "rb").read()).decode("utf-8").replace("\n", "") return fig3, fig4
def plot_state_detection(state_probabilities, start=0, end=100, **kwargs): state_probabilities = pd.DataFrame(state_probabilities[ start:end, :11]) # convert to dataframe and remove null joyplot(state_probabilities, kind='values', x_range=range(end - start), colormap=cm.cool, title='State reactivation probability', alpha=1, **kwargs) plt.xlabel("Timepoint")
def main(): eloader, e_pre, _e_post, iloader, i_pre, _i_post = build_loaders( _TRAINING_RUN_ID, _INFERENCE_RUN_ID) assert len(e_pre.features) == 1 assert len(_e_post.features) == 1 assert len(i_pre.features) == 1 assert len(_i_post.features) == 1 e_pre_mat = e_pre[e_pre.features[0]] train_count_frame = pre_poisson_counts(eloader, e_pre_mat) neg_count_frame = train_count_frame.loc[train_count_frame.y == 0] mcpg = neg_count_frame.unscaled_mcpg.sum() tcpg = neg_count_frame.unscaled_tcpg.sum() post_flipper = sample_reflipper(mcpg, tcpg) i_pre_mat = i_pre[i_pre.features[0]] base_count_frame = pre_poisson_counts(eloader, i_pre_mat) _NUM_POST_PERT_TRIALS = 10 perturbations = defaultdict(list) for _, row in base_count_frame.iterrows(): mcpg = row.unscaled_mcpg tcpg = row.unscaled_tcpg for i in range(_NUM_POST_PERT_TRIALS): perturbed = post_flipper(mcpg, tcpg - mcpg, _N_REROLLS) hmfcs = perturbed[:, 0] * row.scale_factor perturbations[f"trial_{i}"].append(hmfcs) trial_cols = dict() for i in range(_NUM_POST_PERT_TRIALS): trial_cols[f"trial_{i}"] = np.concatenate(perturbations[f"trial_{i}"]) # TODO(jsh): These clearly need to be saved out to disk! post_pert_trial_frame = pd.DataFrame(trial_cols) post_pert_trial_frame["base_dsid"] = np.repeat(base_count_frame.index, _N_REROLLS) slice_reflippers = per_slice_sample_reflippers(e_pre) perturbed_pre_x = find_or_build_perturbed_x(i_pre, slice_reflippers) perturbed_pre_x[..., 1] += perturbed_pre_x[..., 0] perturbed_pre_rmds = build_new_metas(i_pre_mat.row_metadata, _N_REROLLS) pert_i_pre_mat = i_pre_mat.replace_x_and_axis_metadata( perturbed_pre_x, [perturbed_pre_rmds, *i_pre_mat.axis_metadata[1:]]) pre_pert_count_frame = pre_poisson_counts(eloader, pert_i_pre_mat) post_pert_trial_frame["pre_pert"] = pre_pert_count_frame.reset_index().hmfc for dsid, group in post_pert_trial_frame.groupby("base_dsid"): joypy.joyplot(group, legend=False) plt.savefig(f"post_trials.{dsid}.joyplot.png", dpi=300) pdb.set_trace() return
def plot_layer_gradient(): # Loading all_gradient_hist = {} all_models = ['resnet34', 'plain34'] for models in all_models: all_gradient_hist[models] = torch.load('./Results/' + str(models) + '/model.th')['gradient_hist'] all_gradient_hist[models] = np.array(all_gradient_hist[models]) # to panda data frame epochs = range(1, len(all_gradient_hist[all_models[0]]) + 1) epochs = np.repeat(epochs, len(all_gradient_hist[all_models[0]][0])) df1 = pd.DataFrame(list( zip(epochs, all_gradient_hist[all_models[0]].reshape(-1))), columns=['Epoch', 'Gradient Norm']) df2 = pd.DataFrame(list( zip(epochs, all_gradient_hist[all_models[1]].reshape(-1))), columns=['Epoch', 'Gradient Norm']) # Plots fig1, axe1 = joypy.joyplot(df1, by="Epoch", column="Gradient Norm", fade=True, title=all_models[0] + ' gradient norm', figsize=(5, 8)) fig2, axe2 = joypy.joyplot(df2, by="Epoch", column="Gradient Norm", fade=True, title=all_models[1] + ' gradient norm', figsize=(5, 8)) # fig, ax = plt.subplots(1) # fig.suptitle('Learning curve') # for option in all_options: # color = next(ax1._get_lines.prop_cycler)['color'] # ax.plot(all_train_hist[option][1, :], label='option ' + option + ' train acc', linestyle='', color=color) # ax.plot(all_train_hist[option][3, :], label='option ' + option + ' test acc', linestyle=':', color=color) # ax.set(ylabel='Top1 accuracy (%)') # ax.set(xlabel='epochs') fig1.savefig('./Results/' + all_models[0] + 'layer_gradient', bbox_inches='tight') fig2.savefig('./Results/' + all_models[1] + 'layer_gradient', bbox_inches='tight') plt.show()
def plot_ridge_plot(weeks, count_dict): new_weeks = [] ridge_dict = defaultdict(list) for key, value in count_dict.items(): ridge_dict["Week_commencing"].extend(weeks) ridge_dict["Number_adm2_regions"].extend(value) for i in range(len(value)): ridge_dict["Lineage"].append(key) ridge_df = pd.DataFrame(ridge_dict) fig, axes = joypy.joyplot(ridge_df, by="Lineage", column="Number_adm2_regions", figsize=(20, 20), kind="values", ylim='own', x_range=(0, len(weeks)), colormap=plt.cm.GnBu) axes[-1].set_xticks(range(len(weeks))) axes[-1].set_xticklabels(weeks, rotation=90)
def plot_T2spectra(N_voxels, XSol, T2s, path, figure_name, factor): data_xsol_true={} #maxval = 28 maxval = 60 for it in range(0, N_voxels): num_obj = repr(obj0(it+1)) data_xsol_true[num_obj] = XSol[it, 0:maxval] #end for num_obj = repr(obj0(0)) mean_Xsol = np.mean(XSol, axis=0) data_xsol_true[num_obj] = mean_Xsol[0:maxval] * factor # scaling the mean T2 hist, to get scaled spectra data_dist_true = pd.DataFrame(data_xsol_true) T2s = T2s[0:maxval] T2sr = np.int16(np.round(T2s)) labels = [ y for y in list(T2sr) ] overlap = 1.0 fig10, ax10 = joypy.joyplot( data_dist_true, kind="values", x_range=[0, maxval], fade=True, linewidth=1, figsize=(8,8), labels=labels, ylabels=True, overlap=overlap, range_style='own', grid='both', title=figure_name, colormap=lambda x: color_gradient(x) ) xlocs_old, xlabels_old = plt.xticks() xlabels_new = [10, 20, 30, 40, 70, 200, 500, 1000, 2000] xlocs_new = np.zeros((len(xlabels_new))) for iter in range(0, len(xlabels_new)): xlocs_new[iter] = np.interp(xlabels_new[iter], T2s, range(0, maxval)) # plt.xticks(xlocs_new, xlabels_new) plt.gca().set_xlabel('T2 (ms)', size=20) plt.gca().set_ylabel('Mean T_2 of non-dominant lobe (ms)', size=20) plt.savefig(path + figure_name + '.png', dpi=600) # plt.show() plt.close('all')
def plot_joypy_1d(self, x_test, y_test): '''Makes a joypy-plot of the projected data for 1D. Note: requires the joypy plotting library Args: x_train [numpy.array]: test data with observations along axis 0 and features along axis 1, e.g. shape = (5, 3) contains 5 samples with 3 features each y_train [numpy.array]: test labels ''' # joypy plots import joypy if self.num_dims != 1: print( 'Please fit the classifier to 1 dim reduced space in order to plot' ) else: x_proj = np.dot(self.w, x_test.T).T result_df = pd.DataFrame(list(zip(np.squeeze(x_proj.real), y_test)), columns=['x_proj', 'label']) fig, axes = joypy.joyplot(result_df, column='x_proj', by='label', colormap=co.cm.thermal, grid=True, xlabelsize=12, ylabelsize=12) plt.title('Histograms from projection onto 1d space', fontsize=16, fontweight='bold') plt.xlabel('LDA axis', fontsize=14)
def visualize_column_error_label(column, error_label_name, outliers_threshold=2): # Get and prepare data x = np.array(column.values.tolist()) x = np.transpose(x) x = np.array([sorted(base) for base in x]) # Calculate original_data_size = x.shape[0] * x.shape[1] cut_index = _find_cut_index(x, outliers_threshold) x = x[:, :cut_index] cut_data_size = x.shape[0] * x.shape[1] data_percentage = cut_data_size / original_data_size * 100 df = pd.DataFrame() for base_index in range(x.shape[0]): df[base_index] = x[base_index] f, _ = joypy.joyplot( df, overlap=2, colormap=cm.OrRd_r, linecolor='black', linewidth=0.5, fade=True, figsize=(5, 12), title= f"{error_label_name} distributions for bases across all examples (without examples " f"containing outlier for even one base - {data_percentage:.2f}% of data)" )
def plot_pleasures(data, col_1, col_2, population_name=None, title=None): if title is None: title = f"{col_2} by {col_1}\n{population_name} population" fig, axes = joypy.joyplot( data, by=col_1, column=col_2, range_style='own', grid=False, xlabels=False, linewidth=1, legend=False, title=title, bins=40, ylabels=False, overlap=0.9, figsize=(8, 10.5), fill=True, kind="counts", # The Unknown Pleasures colour scheme is set here: background='k', linecolor='w', color='k') # plot.subplots_adjust(left=0, right=1, top=1, bottom=0) return data, fig, axes
def format_perc_recovered_for_joyplot(perc_recovered): months = [{ "March": 61.0 }, { "April": 92.0 }, { "May": 122.0 }, { "June": 153.0 }] n_sample = len(list(perc_recovered[0].values())[0]) data = pd.DataFrame() for month_dict in months: data[list(month_dict.keys())[0]] = "" data["Age"] = "" i = 0 for sample_index in range(n_sample): for agegroup in perc_recovered: month_values = [] for month_dict in months: time = list(month_dict.values())[0] month_values.append( perc_recovered[agegroup][str(time)][sample_index]) data.loc[i] = month_values + ["age_" + str(agegroup)] i += 1 plt.figure(dpi=380) fig, axes = joypy.joyplot(data, by="Age", column=[list(d.keys())[0] for d in months]) plt.savefig('figures/test.png')
def unknown_pleasures_fitness_by_generation(pop_name, island=None): pop_dirs = population_dirs(pop_name, island) data = ft.reduce(pd.DataFrame.append, [ dataframe_for_dir(pop_dir, "generation", "fitness", generation_of_creature, fitness_of_creature) for pop_dir in pop_dirs ]) min_fit = min(data['fitness']) max_fit = max(data['fitness']) left = max_fit * 1.1 right = min_fit * 0.9 fig, axes = joypy.joyplot( data, by="generation", column="fitness", range_style='own', grid=False, xlabels=False, linewidth=1, legend=False, title=f"Fitness density by generation, for {pop_name} population", bins=40, ylabels=False, overlap=0.9, fill=True, kind="counts", # The Unknown Pleasures colour scheme is set here: background='k', linecolor='w', color='k') #plot.subplots_adjust(left=0, right=1, top=1, bottom=0) return data, fig, axes
def joyplot(model, test, max_j=2): y = test[0][1] x_, y_ = np.random.randint(low=0, high=y.shape[1], size=2) dists = [] time_d = [] x_series = [] for j, (x, y) in enumerate(test): if j >= max_j: break batch_size = x.shape[0] for i in range(batch_size): pred = model(np.array([x[i, :, :, :]])) d = getDist(pred[:, :, :, 1:], nBinom) dists.append(np.array(d[0, x_, y_, :])) x_series.append(np.arange(0, 255)) import joypy dframe = pd.DataFrame(np.array(dists[:50]).T) fig, axes = joypy.joyplot(dframe, figsize=(5, 10), linewidth=0.5, grid='y', background='k', x_range=[1, 50], colormap=cm.rainbow)
def JoyPlot(self): # !pip install joypy # Import Data mpg = pd.read_csv("dataVset/mpg_ggplot2.csv") # Draw Plot #plt.figure(figsize=(16, 10), dpi=80) fig, axes = joypy.joyplot(mpg, column=['hwy', 'cty'], by="class", ylim='own', figsize=(14, 10)) # Decoration plt.title('Joy Plot of City and Highway Mileage by Class', fontsize=22) """"" mean = mpg['cty'].mean() median = mpg['cty'].median() mode = mpg['cty'].mode().get_values()[0] variance = statistics.variance(mpg['cty']) stdev = statistics.stdev(mpg['cty']) plt.axvline(mean, color='r', linestyle='--') plt.axvline(median, color='g', linestyle='-') plt.axvline(mode, color='b', linestyle='-') plt.axvline(variance, color='r', linestyle='-') plt.axvline(stdev, color='b', linestyle='--') plt.legend({'Mean': mean, 'Median': median, 'Mode': mode, 'variance': variance, 'standard deviation': stdev}) """"" plt.show()
def PlotWaterFall(self): """活跃时间瀑布图""" fontsize = 20 st = time.time() fig, axes = joypy.joyplot(self.frequent, column=['hour'], by="date", grid=True, xlabelsize=fontsize, ylabelsize=fontsize, figsize=(10, 6), ylim='own', fill=True, linecolor=None, background=None, xlabels=True, ylabels=True, range_style='all', x_range=np.arange(25), color=cm.hsv(0.68)) # params plt.xlabel(u"小时", fontsize=fontsize) plt.xticks(ticks=list(range(0, 24, 4)) + [24], labels=list(range(0, 24, 4)) + [24], fontsize=fontsize) plt.title(u"近一周学习情况", fontsize=fontsize + 5) plt.grid(linestyle="--", alpha=0.45) plt.savefig(self.fig_path, dpi=150, bbox_inches='tight') plt.close()
def plot_histogram(log, name='ah'): colors = cm.OrRd_r(np.linspace(.2, .6, 10)) min_bin = [] max_bin = [] for n, dict in enumerate(log): hist, bins = dict[name] min_bin.append(bins[0]) max_bin.append(bins[-1]) min_bin = min(min_bin) max_bin = max(max_bin) x = np.linspace(min_bin, max_bin, num=100) y = [] for n, dict in enumerate(log): hist, bins = dict[name] if len(bins) == 1 or n % 10 != 0: continue center = (bins[:-1] + bins[1:]) / 2.0 y.append(np.interp(center, center, hist)) fig, ax = joypy.joyplot(y, overlap=2, colormap=cm.OrRd_r, linecolor='w', linewidth=.5) plt.savefig(f"{name}.png") plt.close(fig)
def make_figure(ns, nb, antibody_selection, g): tmp = df.copy() tmp['gene_exp'] = get_exp_gene(g) AB1 = antibody_selection[0] AB2 = antibody_selection[1] tmp[AB1] = antibody_df.loc[AB1] tmp[AB2] = antibody_df.loc[AB2] title = "Number of cells<br> %s" % (str( tmp["Channel"].value_counts().to_json()).replace(",", "<br>")) fig1 = px.scatter( tmp, x=AB1, y=AB2, color='gene_exp', symbol="Channel", hover_data=['barcodekey', 'n_genes', 'n_counts', 'louvain_labels'], opacity=0.5, size_max=3, template="simple_white", title=title) fig1.update_layout(coloraxis_colorbar=dict( yanchor="top", y=0.5, x=1, ticks="outside", len=0.5)) fig2 = px.scatter( tmp, x="UMAP1", y="UMAP2", color='gene_exp', symbol="Channel", hover_data=['barcodekey', 'n_genes', 'n_counts', 'louvain_labels'], opacity=0.5, size_max=3, template="simple_white", title=title) fig2.update_layout(coloraxis_colorbar=dict( yanchor="top", y=0.5, x=1, ticks="outside", len=0.5)) joypy.joyplot(tmp, by="Channel", ylim='own', column="gene_exp") plt.savefig("test.png", bbox_inches='tight') s2 = base64.b64encode(open("test.png", "rb").read()).decode("utf-8").replace("\n", "") return fig1, fig2, [ html.Img(id="plot", src="data:image/png;base64,%s" % (s2)) ]
def joy_plot(name, sample_size): # Get data name = 'nitrate' sample_size = 100 month_list = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] # week_list = [i+1 for i in range(52)] tech_list = ['AS', 'ASCP'] df_AS = pd.DataFrame() df_ASCP = pd.DataFrame() df_EBPR = pd.DataFrame() df_EBPR_FBR = pd.DataFrame() instance_AS = WWT_SDD(tech=tech_list[0]) np_instance_AS = instance_AS.run_model(sample_size, period='month')[1] instance_ASCP = WWT_SDD(tech=tech_list[1]) np_instance_ASCP = instance_ASCP.run_model(sample_size, period='month')[1] # process data into required format # Nitrate, TSS, TP, COD, TN if name == 'nitrate': p = 0 elif name == 'TSS': p = 1 elif name == 'TP': p = 2 elif name == 'COD': p = 3 else: p = 4 for i in range(12): df2 = pd.DataFrame(np_instance_AS[i,:,p]) df2.columns = [name +'_' + tech_list[0]] df2['Month'] = i+1 df_AS = df_AS.append(df2, ignore_index=True) for i in range(12): df2 = pd.DataFrame(np_instance_ASCP[i,:,p]) df2.columns = [name +'_' + tech_list[1]] df2['Month'] = i+1 df_ASCP = df_ASCP.append(df2, ignore_index=True) df_combined = pd.concat([df_AS,df_ASCP], axis=1) df_combined = df_combined.loc[:,~df_combined.columns.duplicated()] # df_combined = df_combined[[df_AS.columns[0], df_ASCP.columns[0], 'Month']] # df_combined_log = np.log10(df_combined.iloc[:,0:2]) # df_combined_log['Month'] = df_combined['Month'] plt.figure(figsize=(6.5,11)) fig, axes = joypy.joyplot(df_combined, column=[df_AS.columns[0], df_ASCP.columns[0]], by="Month", ylim='own', figsize=(6.5,11), legend=True, alpha=0.8, labels=month_list, ylabelsize=14,color=['blue','green']) plt.title(name + ' effluent by month', fontsize=14) plt.xlabel(name + ' effluent (mg/L)', fontsize=14) # axes[:-1][0].xaxis.set_major_formatter(mticker.StrMethodFormatter("$10^{{{x:.0f}}}$")) # ax = axes[:-1][-1] # axes[:-1][0].xaxis.set_ticks([np.log10(x) for p in range(-6,1) # for x in np.linspace(10**p, 10**(p+1), 10)], minor=True) # plt.xlim(0,20) # for a in axes[:-1]: # a.set_xscale('log') plt.tight_layout() # plt.savefig('./model_WWT/SDD_analysis'+ '/Joyplot_'+name+'.tif',dpi=300) plt.show()
def make_figure_subset(selectedPoints, antibody_selection, g): if selectedPoints == None: return None, None, None # customdata index_list = [x['customdata'][0] for x in selectedPoints['points']] # print (len(index_list),index_list[0]) tmp = df.copy() tmp['gene_exp'] = get_exp_gene(g) tmp = tmp.loc[index_list] joypy.joyplot(tmp, by="Channel", ylim='own', column="gene_exp") plt.savefig("test2.png", bbox_inches='tight') s2 = base64.b64encode(open("test2.png", "rb").read()).decode("utf-8").replace("\n", "") return [html.Img(id="plot", src="data:image/png;base64,%s" % (s2))]
def duplicates(): df = get_duplicate_data() df['error'] = df["POSIX_AGG_PERF_BY_SLOWEST_LOG10"] - df["prediction"] df = df[np.abs(df.error) < np.log10(1.5)] df.time_diff = np.log10(df.time_diff + 0.01) # df.error = np.abs(df.error) cuts = [-np.inf] + list(range(9)) groups = [ df[(df.time_diff >= low) & (df.time_diff < high)].error for low, high in zip(cuts[:-1], cuts[1:]) ] # fit a student t distribution from scipy.stats import t param = t.fit(groups[0]) norm_gen_data = t.rvs(param[0], param[1], param[2], 10000) groups = list(reversed([norm_gen_data] + groups)) labels = list( reversed(["t-distribution fit", "0s to 1s"] + [ "$10^{}s$ to $10^{}s$".format(low, high) for low, high in zip(cuts[1:-1], cuts[2:]) ])) fig, axes = joypy.joyplot(groups, colormap=matplotlib.cm.coolwarm_r, overlap=0.3, linewidth=1., ylim='own', range_style='own', tails=0.2, bins=100, labels=labels, figsize=(2.5, 3)) for idx, ax in enumerate(axes): try: ax.set_yticklabels([labels[idx]], fontsize=8, rotation=120) except: pass ax.set_xlim([-0.2, 0.2]) ax.set_xticks(np.log10([1 / 1.5, 1 / 1.2, 1, 1.2, 1.5])) ax.set_xticklabels([ "$.67\\times$", "$.83\\times$", "$1\\times$", "$1.2\\times$", "$1.5\\times$" ], rotation=90, fontsize=8) plt.xlabel("Error", rotation=180) plt.ylabel("Time ranges") plt.savefig("figures/figure_5.pdf", dpi=600, bbox_inches='tight', pad_inches=0)
def showgraph(graph_selection, liste_annee, liste_ville, liste_specialite): if graph_selection == "Carte Thermique": df = pd.read_csv('data/2_aggregates/agg_latest_spot.csv', index_col=0) df = df[df.ville.isin(liste_ville) & df.specialite.isin(liste_specialite) & df.annee.isin(liste_annee)] fig = px.density_heatmap(df, x="ville", y="specialite", z="classement", histfunc="avg") st.plotly_chart(fig, use_container_width=True) if graph_selection == "Boites à Moustaches": st.write("WIP") if graph_selection == "Résulats par Ville à travers le temps": df = df.groupby(['ville', 'annee']).max() df = df.reset_index(level=['ville', 'annee']) st.write(df) fig = px.line(df, x="annee", y="classement", color='ville') st.plotly_chart(fig, use_container_width=True) if graph_selection == "Résulats par Spécialité à travers le temps": fig = px.line(df, x="annee", y="classement", color='specialite') st.plotly_chart(fig, use_container_width=True) if graph_selection == "Lignes de crêtes par Ville": df_full = pd.read_csv('data/2_aggregates/full.csv', index_col=0) df_full = df_full[df_full.ville.isin(liste_ville) & df_full.specialite.isin(liste_specialite) & df_full.annee.isin(liste_annee)] plt.figure() joyplot(data=df_full[['classement', 'ville']], by='ville', figsize=(12, 8), linecolor="blue", colormap=cm.autumn_r) plt.title('Ligne de crête des classements par ville', fontsize=20) st.pyplot(plt, use_container_width=True) if graph_selection == "Lignes de crêtes par Spécialité": st.write("WIP")
def _show3d(_block, indexForGet): fig = plt.figure() fig.canvas.set_window_title( getValues(allRawStats[0], indexForGet)[1] + " - " + showName) ax = fig.add_subplot(111, projection='3d') # make the under-the-hood y-values: ys = [] yLabels = [] y_cumulative = 0 for it in allRawStats: y_cumulative += it["weight"] ys.append(y_cumulative) yLabels.append("%7.2f" % it["z"]) ax.set_yticks(ys) ax.set_yticklabels(yLabels) ax.set_xlabel("Flux ratio") ax.set_ylabel("z") ax.set_zlabel("Count") # Log scale doesn't seem to play well. # ax.set_xscale("log", nonposx='clip') forJoyPlot = [] firstBarx = None for i in range(len(allRawStats)): it = allRawStats[i] zPos = ys[i] thisBinned = ValueBinner.BinThis(getValues(it, indexForGet)[0], nBins=nBins, linLog="linear", fixRange=fixRange)[0] barx, barw, barh = thisBinned.makeBarPlotData() ax.bar(barx, barh, width=barw, align="center", zs=zPos, zdir='y', alpha=0.8) forJoyPlot.append(barh) firstBarx = barx fig, ax = joypy.joyplot(forJoyPlot, kind="values", x_range=[i for i in range(len(firstBarx))], xlabels=[str(it) for it in firstBarx], ylabels=yLabels, labels=yLabels, colormap=cm.autumn_r, linewidth=0.5, figsize=(4, 4)) fig.canvas.set_window_title( getValues(allRawStats[0], indexForGet)[1] + " - " + showName) # plt.show(block = _block) return
def test_groupby_hist(iris): fig, axes = joypy.joyplot(iris, by="Name", column="SepalWidth", hist="True", bins=20, overlap=0, grid=True, legend=False)
def ridge_plot_wo_overlap(df, by, column, figsize, colormap): plt.rcParams['axes.labelsize'] = 14 plt.rcParams['xtick.labelsize'] = 14 plt.tight_layout() # Make ridge plot fig, axes = joypy.joyplot(data=df, by=by, column=column, figsize=figsize, colormap=colormap, linewidth=1, overlap=0) # Add x-axis label axes[-1].set_xlabel(column)
def visualize_column_normal_label(column): x = np.array(column.values.tolist()) df = pd.DataFrame(x) display(df.describe()) fig, axes = joypy.joyplot(df, overlap=2, colormap=cm.OrRd_r, linecolor='black', linewidth=0.5, fade=True, figsize=(24, 12)) plt.show(fig)
def get_mcp_hist(self): """Method that makes a histogram of different motif lengths by project.""" if not self.project_stats_created: self.make_proj_stats_df() df = self.project_stats[['mcp_5', 'mcp_10', 'mcp_25', 'mcp_50', 'mcp_100']] df.columns = ['Length 5', 'Length 10', 'Length 25', 'Length 50', 'Length 100'] fig, axes = joypy.joyplot(df, title='Distribution of Commit Chains With at Least \n One Branch or Merge, by Chain Length') axes[-1].set_xlabel('Ratio of Chains With at Least One Branch or Merge') fig.tight_layout() fig.savefig('results/mcp_histograms.png') return fig
def test_temperature(temp): labels = [y if y % 10 == 0 else None for y in list(temp.Year.unique())] fig, axes = joypy.joyplot( temp, by="Year", column="Anomaly", labels=labels, range_style='own', grid="y", linewidth=1, legend=False, figsize=(6, 5), title="Global daily temperature 1880-2014 \n(°C above 1950-80 average)", colormap=cm.autumn_r)
def joyplotting(): test = df_heart.copy() test['male'] = test['male'].replace([0, 1], ['female', 'male']) plt.tight_layout() plt.figure(figsize=(16, 10), dpi=600) fig, axes = joyplot(test, column='TenYearCHD', by='male', ylim='own', figsize=(14, 10), colormap=cm.autumn_r) plt.title('Label distribution per gender') plt.savefig(os.path.join(figures_path, 'label per gender'), bbox_inches='tight') plt.show()
with open("../results/tradeoff.pickle", "rb") as pick: solutions = pickle.load(pick) def get_members(sol): return sol.apply(lambda s: s.members.drop("medium")).iloc[0] rates = (solutions.groupby(["tradeoff", "sample"]).solution. apply(get_members).reset_index()) rates.growth_rate /= community_mass rates["log_rates"] = np.log10(rates.growth_rate) rates.loc[rates.growth_rate <= 0, "log_rates"] = -18 fig, axes = jp.joyplot(rates, by="tradeoff", column="log_rates", color="cornflowerblue") lf = LogFormatterMathtext() xax = axes[-1].xaxis xax.set_ticklabels(lf(10.0**ex) for ex in xax.get_ticklocs()) plt.xlabel("growth rate [1/h]") plt.ylabel("tradeoff") plt.savefig("dists.svg") plt.close() non_zero = rates.groupby(["sample", "tradeoff"]). \ apply(lambda df: (df.growth_rate > 1e-6).sum()).reset_index(name="non_zero") n_genus = rates.groupby("sample").compartments.nunique() plt.axhline(n_genus.mean(), color="k", linestyle="dashed") g = sns.boxplot("tradeoff", "non_zero", data=non_zero, color="w", fliersize=0) g = sns.stripplot("tradeoff", "non_zero", data=non_zero, color="k",