def aggr_and_write_utils(aggr_df, outdir): max_utils = [] util_vals = [] grouping = aggr_df.groupby(["frame_id", "vid_name"]) for key in grouping.groups.keys(): (frame_id, vid_name) = key gdf = grouping.get_group(key) aggr = gdf.agg({"utility": "max", "label": "max"}) max_utils.append([frame_id, vid_name, aggr["utility"], aggr["label"]]) util_vals.append(aggr["utility"]) max_utils_df = pd.DataFrame( max_utils, columns=["frame_id", "vid_name", "utility", "label"]) plt.close() sns.ecdfplot(data=max_utils_df, x="utility") plt.savefig(join(outdir, "utils_cdf.png"), bbox_inches="tight") util_vals = sorted(util_vals) cdf_points = 100 idx_steps = math.ceil(len(util_vals) / cdf_points) curr_idx = 0 with open(join(outdir, "util_cdf.txt"), "w") as f: while curr_idx < len(util_vals): f.write("%f\t%f\n" % (curr_idx / len(util_vals), util_vals[curr_idx])) curr_idx += idx_steps f.write("%f\t%f\n" % (1.0, util_vals[-1]))
def make_emb_dist_plot(da_an_dist, da_ad_dist, an_dist_threshold, ax=None): # anchor neighbour distance distribution if ax is None: fig, ax = plt.subplots() else: fig = ax.figure n_peak_widths = 5 n_bins_till_peak = 5 xlim_max = an_dist_threshold * n_peak_widths kwargs = dict( ax=ax, range=(0, xlim_max), bins=n_bins_till_peak * n_peak_widths, histtype="step", ) da_an_dist.plot.hist(label="a-n dist", color="b", **kwargs) da_ad_dist.plot.hist(label="a-d dist", color="g", **kwargs) ax.legend() ax.set_xlim(0, xlim_max) ax.set_ylabel("num pairs [1]") ax_twin = ax.twinx() sns.ecdfplot(da_an_dist, ax=ax_twin, color="b") ax_twin.axvline(an_dist_threshold, color="b", linestyle="--") sns.ecdfplot(da_ad_dist, ax=ax_twin, color="g") return (fig, ax)
def plot_null_ecdf(results): fig, ax = plt.subplots(1, 1, figsize=(6, 6)) sns.ecdfplot(data=results[results["str_delta"] == "0.000"], x="pvalue") ax.set(xlabel="p-value", ylabel="Cumulative density", title=r"ECDF under $H_0$") ax.plot([0, 1], [0, 1], color="darkred", linestyle="--", zorder=-1) return ax
def prueba_emp_disc(): p = np.random.randint(1, 100, 50) p = estandarizar(p) b = sorted(random.sample(range(1, 50 * 2), 50)) emp_disc_sus = [] for i in range(100): emp_disc_sus.append(dist_emp_discr(b, p, 50)) sns.ecdfplot(emp_disc_sus) plt.show()
def plot_connection_solver_execution_time_ecdf( execution_time: pd.Series) -> plt.Figure: fig, ax = plt.subplots(figsize=(6, 4)) sns.ecdfplot(execution_time, ax=ax) sns.rugplot(execution_time, linewidth=0.2, alpha=0.5, ax=ax) ax.set(xlabel='Czas wyszukiwania połączeń [s]', ylabel='Procent przetworzonych zapytań', ylim=(-0.03, 1.03)) ax.yaxis.set_major_formatter(PercentFormatter(1.0)) return fig
def plot_ecdf(df, var, target, ax): """ Plot 1D ECDF """ sns.ecdfplot( ax=ax, data=df, x=var, hue=target, legend=False, )
def plot_cdf_distance(df): df = df[df["improved"]] print("Fraction of repair with distance > 10") df = df.copy() df["distance_over_10"] = df["distance"] > 10.0 print(df.groupby("strategy")["distance_over_10"].mean()) fig, ax = plt.subplots(1) sns.ecdfplot(data=df, x="distance", hue="strategy", ax=ax) ax.set_xlabel("Edit distance\n(improved pipelines)") ax.set_ylabel("Empirical CDF") plt.tight_layout() return ax
def generate_plots(filename): df = pd.read_csv(filename, names=['request_type', 'latency']) # plot cdf sns.ecdfplot(df, x="latency", hue="request_type") # save them to their respective directory plt.savefig("{}//cdf_plot.png".format(os.path.dirname(filename)), format='png', dpi=150) # clear the plot plt.clf()
def PlotAll(pd_data, x, y, hue, ylim, figsize, outfile): plt.style.use(['my-paper', 'my-line']) figsize = [int(i) for i in re.split(':', figsize)] fig, axe = plt.subplots(figsize=(figsize[0], figsize[1])) if hue: if x: sns.ecdfplot(data=pd_data, x=x, hue=hue,) elif y: sns.ecdfplot(data=pd_data, y=y, hue=hue,) else: if x: sns.ecdfplot(data=pd_data, x=x, ) elif y: sns.ecdfplot(data=pd_data, y=y, ) plt.setp(axe.spines.values(), linewidth=3) axe.xaxis.set_tick_params(width=0, length=0) # axe.xaxis.set_ticklabels([]) axe.yaxis.set_tick_params(width=3, length=10) if ylim: min_v, max_v=[int(i) for i in re.split(':', ylim)] axe.set_ylim(min_v, max_v) axe.set_xlabel(x, size = 40) axe.set_ylabel(y, size = 40) axe.set_yticks(axe.get_yticks()[1:]) plt.xticks(size = 30) plt.yticks(size = 30) # axe.legend(loc='lower right') plt.savefig(outfile, dpi=300)
def plotMatrix(model, A, mat_name): fig_path = os.path.join(model.fig_dir, "matrix_{:}.png".format(mat_name)) # plot matrix visualizations fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(12, 6)) foo = ax[0].matshow(A, vmin=np.min(A), vmax=np.max(A), aspect='auto') # ax[0].axes.xaxis.set_visible(False) # ax[0].axes.yaxis.set_visible(False) ax[0].set_title(mat_name) fig.colorbar(foo, ax=ax[0]) sns.ecdfplot(data=np.abs(A).reshape(-1, 1), ax=ax[1]) ax[1].set_xscale('log') ax[1].set_title('Distribution of matrix entries') plt.savefig(fig_path) plt.close()
def plot_histogram(df, col_name: str): """Plots two distribution plots - an histogram and a emprical cumulative distribution - of the selected variable. """ import matplotlib.pyplot as plt import seaborn as sns df_copy = df.copy() median_val = df_copy[col_name].median() axis_format = plt.FuncFormatter(lambda x, loc: f"{int(x):,}") axis_format_prcnt = plt.FuncFormatter(lambda x, loc: f"{x:,.1%}") fig, axes = plt.subplots(2, 1, figsize=(12, 8), sharex=True) hist = sns.histplot(df_copy[col_name], kde=True, ax=axes[0]) hist.get_yaxis().set_major_formatter(axis_format) hist.axvline(median_val, linewidth=4, linestyle="--", color='black') hist.set_title(f"Median '{col_name}' is {median_val:,}") ecd = sns.ecdfplot(df_copy[col_name], ax=axes[1]) ecd.get_yaxis().set_major_formatter(axis_format_prcnt) ecd.set_title(f"Cumulative Distribution of Records by '{col_name}") plt.suptitle(f"Distribution of Records by '{col_name}'", size=16) plt.show()
def wogive(self, **kwargs): """Weights empirical cumulative distribution plot. In statistics, an empirical distribution function (eCDF) is the distribution function associated with the empirical measure of a sample. This cumulative distribution function is a step function that jumps up by 1/n at each of the n data points. Its value at any specified value of the measured variable is the fraction of observations of the measured variable that are less than or equal to the specified value. .. _empirical distribution function: https://en.wikipedia.org/wiki/Empirical_distribution_function Parameters ---------- **kwargs Additional keyword arguments are passed and are documented in ``seaborn.ecdfplot``. Returns ------- matplotlib.axes.Axes or numpy.ndarray of them """ ax = sns.ecdfplot(data=self._wdf, **kwargs) return ax
def plot(dfs, filters, plot_name, custom): if custom == "locust": for df in dfs: sns.lineplot(data=df, x="Latency (ms)", y="Percent") plt.legend(labels=filters) plt.xlim(0, 1000) plt.title(plot_name) elif custom == "fortio": for df in dfs: sns.lineplot(data=df, x="Latency (ms)", y="Percent") plt.legend(labels=filters) plt.title(plot_name) elif custom == "loadgen": fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(18, 6)) dplot = sns.ecdfplot(dfs, ax=ax1) dplot.set(xlabel="Latency (ms)", ylabel="Percentiles") dplot.set_title(plot_name) hplot = sns.histplot(dfs, ax=ax2) hplot.set(xlabel="Latency (ms)", ylabel="Count") else: log.info("No valid load generator supplied!") return util.EXIT_FAILURE util.check_dir(GRAPHS_DIR) plt.savefig(f"{GRAPHS_DIR}/{plot_name}.png") log.info("Finished plotting. Check out the graphs directory!") return util.EXIT_SUCCESS
def main(rel, dir, name, size): df = pd.DataFrame() if rel == 1: df = load_rate(dir, 1, df, size) #df = load_rate(dir, 10, df, size) df = load_rate(dir, 100, df, size) df = load_rate(dir, 1000, df, size) elif rel == 2: df = load_rate(dir, 100, df, size) df = load_rate(dir, 1000, df, size) elif rel == 3: df = load_rate2(dir, 1, df, size) #df = load_rate2(dir, 10, df, size) elif rel == 4: #df = load_rate2(dir, 102, pd.DataFrame(), size) df = load_rate2(dir, 1000, df, size) print(df) if args.kde: g = sns.kdeplot(data=df, cumulative=True) elif args.cdf: g = sns.ecdfplot(data=df) g.set(xlabel = 'Latency ($u$s)', ylabel = 'Cumulative Distribution Function') elif args.cat: g = sns.catplot(data=df) elif args.bar: sns.catplot(data=df, kind="bar") elif args.box: sns.boxplot(data=df) elif args.his: sns.histplot(data=df) plt.savefig(f"{name}_{rel}2.pdf") plt.show()
def plot_cdf_score_diff(df): df = df.copy() # don't count pipelines that were originally broken df = df[~pd.isnull(df["mean_test_score_orig"])] # but for cases where the repaired is broken # we say that it gets score 0.0 df["mean_test_score_repaired"] = df["mean_test_score_repaired"].fillna(0.0) df["score_diff"] = df["mean_test_score_repaired"] - df[ "mean_test_score_orig"] assert not pd.isnull(df["score_diff"]).any() fig, ax = plt.subplots(1) sns.ecdfplot(data=df, x="score_diff", hue="strategy", ax=ax) ax.set_xlabel("Pipeline score change") ax.set_ylabel("Empirical CDF") plt.tight_layout() return ax
def lqdassetsViz(df, targetdir, stat="count", weighted=False, both=False): if weighted & both: weights = df.weighting.values weights_str = " (Weighted and Unweighted)" elif weighted: weights = df.weighting.values weights_str = " (Weighted)" else: weights = None weights_str = " (Unweighted)" title = f"Cumulative Distribution of Liquid Assets\nAmong U.S. Households{weights_str}" xvar = 'lqd_assets' # Set up the matplotlib figure fig, ax = plt.subplots(figsize=(15, 12)) sns.ecdfplot(x=df[xvar], linewidth=4.5, stat=stat, weights=weights, color='#8A2423') if weighted & both: sns.ecdfplot(x=df[xvar], linewidth=4.5, stat=stat, weights=None, color='#303030') fig.legend(labels=["Weighted", "Unweighted"], loc="center right") # Adjust count for readability if stat == "count": ax.get_yaxis().set_major_formatter( matplotlib.ticker.FuncFormatter(lambda x, p: format(int(x), ','))) # Labels and titles ax.set(title=f'{title}', xlabel=labels_dict[xvar]) #log scale ax.set(xscale="log") plt.tight_layout() fig.savefig(f'{targetdir}{title}.png', bbox_inches='tight') return plt.show()
def tail(self, tail=0.01): _, __ = plt.subplots(1,1) edges_weight = [self.net[u][v]['weight'] for u, v in self.net.edges()] df = pd.DataFrame({'weight':edges_weight}) g = sns.ecdfplot(data=df, x='weight', complementary=True, stat='proportion', ax=__) line = np.array(g.lines[0].get_data()) intersection = line[0][np.argwhere(np.diff(np.sign(line[1]-tail)))] plt.close(_) return intersection[0][0]
def main(argv): try: loading_csv_file = argv[1] except IndexError: print(f"usage: {argv[0]} LOADING_TIMES_CSV_FILE [OUTPUT_PREFIX]") return if len(argv) > 2: out_prefix = argv[2] else: out_prefix = "./loading-" plt.style.use(PYPLOT_STYLE) COLORS = plt.rcParams['axes.prop_cycle'].by_key()['color'] policy_styles = { 'vanilla': ('Permissive', COLORS[0], '+'), 'page-length': ('Page-length', COLORS[1], '^'), 'split-key': ('Site-keyed', COLORS[2], 'o'), 'block3p': ('Blocking', COLORS[3], 'x'), } temp_line_styles = { 'cold': ("cold", '-'), 'hot': ("hot", ':'), } df = pd.read_csv(loading_csv_file) for metric, mdata in df.groupby('metric'): ax = None series_map = { series: sdata.seconds for series, sdata in mdata.groupby(['policy', 'temp']) } max_x = 0.0 for policy, (ptext, pcolor, pmarker) in policy_styles.items(): for temp, (ttext, tls) in temp_line_styles.items(): series = series_map[(policy, temp)] ax = sns.ecdfplot(series, label=f"{ptext} ({ttext})", color=pcolor, marker=pmarker, ls=tls, markevery=500, alpha=0.5, ax=ax) max_x = max(max_x, series.quantile(0.95)) ax.legend() ax.set_xlabel(f"seconds until {metric}") ax.set_ylabel("pages visited (CDF)") #ax.set_title(metric) ax.set_xlim((0, max_x)) fig = ax.get_figure() fig.tight_layout() fig.savefig(f"{out_prefix}{metric}.pdf") plt.close(fig)
def test_DecisionMatrixPlotter_wogive(decision_matrix, fig_test, fig_ref): dm = decision_matrix( seed=42, min_alternatives=3, max_alternatives=3, min_criteria=3, max_criteria=3, ) plotter = plot.DecisionMatrixPlotter(dm=dm) test_ax = fig_test.subplots() plotter.wogive(ax=test_ax) # EXPECTED weights = dm.weights.to_frame() exp_ax = fig_ref.subplots() sns.ecdfplot(data=weights, ax=exp_ax)
def ObsPlot(system,outname,colnum): UList = glob(system+"*.U.obs") LList = glob(system+"*.L.obs") UList.sort() LList.sort() FinalU, FinalL = [[],[],[]], [[],[],[]] label = 0 for Ufile, Lfile in zip(UList,LList): with open(Ufile, 'r') as UF: U_all_lines = UF.read().splitlines() with open(Lfile, 'r') as LF: L_all_lines = LF.read().splitlines() for Uline, Lline in zip(U_all_lines,L_all_lines): if Uline.split()[0] == "Chain:": pass else: FinalU[0].append(float(Uline.split()[0])/10) FinalU[1].append(float(Uline.split()[colnum])) FinalU[2].append(label) if Lline.split()[0] == "Chain:": pass else: FinalL[0].append(float(Lline.split()[0])/10) FinalL[1].append(float(Lline.split()[colnum])) FinalL[2].append(label) label += 1 UObsDF = pd.DataFrame({"Time (ns)": FinalU[0], "Obs": FinalU[1]}) LObsDF = pd.DataFrame({"Time (ns)": FinalL[0], "Obs": FinalL[1]}) fig, ax = plt.subplots() np.set_printoptions(precision=3) plt.xlabel("Obs") ax.set_ylabel("Probability Mass Function") ax = sns.histplot(data=UObsDF,x="Obs",stat='density',label='Upper',legend=False,color="#7400B8") ax = sns.histplot(data=LObsDF,x="Obs",stat='density',label='Lower',legend=False,color="#80FFDB") ax2 = ax.twinx() ax2.set_ylabel("Cumulative Distribution Function") ax2 = sns.ecdfplot(data=UObsDF,x="Obs",stat='proportion',color="#5E60CE") ax2 = sns.ecdfplot(data=LObsDF,x="Obs",stat='proportion',color="#64DFDF") fig.legend() plt.savefig(outname+"_LvsU_Obs.png", dpi=400) plt.clf()
def viz_prop_n_days(data, day_cutoff=8, out_file=None): import matplotlib.pyplot as plt import seaborn as sns # get data nt = get_ntimepoints(data) # plot fig, ax = plt.subplots(1, 1, figsize=(4, 3)) sns.ecdfplot(x='n_days', data=nt, ax=ax, label='All data') sns.ecdfplot(x='n_days', data=nt.groupby('GA').mean().reset_index(), ax=ax, label='GA') sns.ecdfplot(x='n_days', data=nt.groupby('pid').mean().reset_index(), ax=ax, label='Patient') ax.plot([day_cutoff, day_cutoff], [ax.get_ylim()[0], ax.get_ylim()[1]], 'k--') ax.legend(bbox_to_anchor=(1.01, 1)) if out_file is not None: fig.savefig(out_file, bbox_inches='tight') return nt
def plotCDF(fx_df): #print(fx_df) fig, ax = plt.subplots(figsize=(6, 20)) mask = fx_df.isnull() ax = sns.ecdfplot(data=fx_df.filter(like="36C", axis="columns")) plt.tick_params(axis='both', which='major', labelsize=10, labelbottom=True, bottom=False, top=False, labeltop=False) plt.show()
def draw(): sns.histplot(values, bins=bins, kde=kde, binwidth=binwidth, stat=stat, **kwargs) if cdf: if cdfComplementary or stat not in ("count", "proportion"): sns.ecdfplot(values, stat=stat, complementary=cdfComplementary, color="orange") else: sns.histplot(values, bins=100, stat=stat, element="poly", fill=False, cumulative=True, color="orange") if xlabel is not None: plt.xlabel(xlabel)
def test_DecisionMatrixPlotter_ogive(decision_matrix, fig_test, fig_ref): dm = decision_matrix( seed=42, min_alternatives=3, max_alternatives=3, min_criteria=3, max_criteria=3, ) plotter = plot.DecisionMatrixPlotter(dm=dm) test_ax = fig_test.subplots() plotter.ogive(ax=test_ax) # EXPECTED labels = [ f"{c} {o.to_string()}" for c, o in zip(dm.criteria, dm.objectives) ] exp_ax = fig_ref.subplots() sns.ecdfplot(data=dm.matrix, ax=exp_ax) exp_ax.legend(labels)
def orderBook_plot(self): data, frames = self.orderBook_info() fig, ax = plt.subplots() #ax.set_title(f"Last update: {t} (ID: {last_update_id})") sns.ecdfplot(x="price", weights="quantity", stat="count", complementary=True, data=frames["bids"], ax=ax) sns.ecdfplot(x="price", weights="quantity", stat="count", data=frames["asks"], ax=ax) sns.scatterplot(x="price", y="quantity", hue="side", data=data, ax=ax) ax.set_xlabel("Price") ax.set_ylabel("Quantity") plt.show()
def load_dateset(dir, df_): if df_ is None: df_ = pd.DataFrame() f_name = "baseline/pktgen1.txt" df = pd.read_csv(f_name, header=None, names=['lat']) #df_[f'{dir}: {rate} Mpps: {size} Bytes'] = df['lat'] df_[f'10Mpps'] = df['lat'] df = df_ nm = '' if args.kde: g = sns.kdeplot(data=df, cumulative=True) nm = 'kde' elif args.cdf: g = sns.ecdfplot(data=df) g.set(xlabel='Latency ($u$s)', ylabel='Cumulative Distribution Function') nm = 'cdf' elif args.cat: g = sns.catplot(data=df) nm = 'cat' elif args.bar: sns.catplot(data=df, kind="bar") nm = 'bar' elif args.box: sns.boxplot(data=df) nm = 'box' elif args.his: sns.histplot(data=df) nm = 'his' elif args.lin: sns.lineplot(data=df) plt.savefig(f"pktgen1.pdf") plt.show()
#%% Number of customers over the years first = list(customers)[0].registration_date last = list(customers)[-1].registration_date days = np.cumsum( [x.days for x in np.diff([c.registration_date for c in customers])]) steps = [np.argmax(days > i) for i in range(61, max(days), 30)] dates = [customers[i].registration_date.strftime('%b %Y') for i in steps] plt.figure(figsize=[6, 6], maximize=False) pngs = [] for i, s in enumerate(steps): plt.clf() dates = [c.registration_date for c in customers[:s]] x = pd.DataFrame({'dates': dates}) sns.ecdfplot(data=x, x='dates', stat='count') xlim, ylim = plt.xlim(), plt.ylim() plt.xlim(first, last) plt.ylim(0, len(customers)) plt.plot([*plt.xlim()], [*plt.ylim()], '--', c='gray', alpha=0.8) # plt.xlim(xlim) plt.xlabel('Monat', {'fontsize': 16}) plt.ylabel('Anzahl Kunden', {'fontsize': 16}) plt.legend(['Kunden', 'Linearer Anstieg']) plt.title('Anzahl an Kunden seit Eröffnung', {'fontsize': 20}) plt.xticks(rotation=25) plt.tight_layout() plt.pause(0.01) plt.savefig('./plots/tmp.png') img = imageio.imread('./plots/tmp.png') pngs.append(img)
def cdf(complementary=False): plt.figure(figsize=FIGSIZE.BOX_M) sns.set(style="ticks", palette=PALETTE_5) data = {} configs = list() for conf, infos in allInfos.items(): key = f"{conf.scheduler} - {conf.fec}".upper() configs.append(key) data[key] = [] for info in infos: data[key] += filter(lambda x: x < 0.4, info.segment_download_times) data[key] = z_filter(data[key], 1) # fill missing recordings with NaNs maxlen = max([len(data[k]) for k in data.keys()]) for k, v in data.items(): data[k] = v + [float('nan')] * (maxlen - (len(v))) patches = [] for i, config in enumerate(configs): color = sns.color_palette()[i] linestyle = "-" if "S-IOD" in config: color = "orange" linestyle = "-" elif "IOD" in config: color = "goldenrod" linestyle = "--" elif "S-EDPF" in config: color = "royalblue" linestyle = "-" elif "NONE" in config: color = "black" linestyle = ":" elif "LL" in config: color = "black" linestyle = "-" kwargs = { "cumulative": True, "color": color, "linestyle": linestyle, } #ax = sns.distplot(data[config], hist=False, kde_kws=kwargs) ax = sns.ecdfplot(data[config], complementary=complementary, color=color, linestyle=linestyle) patches.append( Line2D( [0], [0], color=color, label=fixname(config), linestyle=linestyle, lw=2, )) ax.set(xlabel='Download Time (s)', ylabel='') plt.legend(handles=patches) if complementary: plt.savefig("vis-dload-ccdf." + FORMAT) else: plt.savefig("vis-dload-cdf." + FORMAT)
sns.histplot(planets, x="year", y="distance", bins=30, discrete=(True, False), log_scale=(False, True),) #legend - annotate the colormap, add a colorbar sns.histplot( planets, x="year", y="distance", bins=30, discrete=(True, False), log_scale=(False, True), cbar=True, cbar_kws=dict(shrink=.75),) # kdeplot - Plot univariate or bivariate distributions using kernel density estimation. # kdeplot([x, y, shade, vertical, kernel, bw, …]) sns.kdeplot(data=penguins, x="flipper_length_mm", hue="species", multiple="stack") # ecdfplot - Plot empirical cumulative distribution functions. # ecdfplot([data, x, y, hue, weights, stat, …]) sns.ecdfplot(data=penguins, x="bill_length_mm", hue="species", stat="count", complementary=True) # stat - Distribution statistic to compute, complementary - if True, use the complementary CDF # rugplot - Plot marginal distributions by drawing ticks along the x and y axes. # rugplot([x, height, axis, ax, data, y, hue, …]) sns.scatterplot(data=tips, x="total_bill", y="tip", hue="time") sns.rugplot(data=tips, x="total_bill", y="tip", hue="time", height=-.02, clip_on=False) # we represent a third variable with hue mapping # Show the density of a larger dataset using thinner lines and alpha blending: diamonds = sns.load_dataset("diamonds") sns.scatterplot(data=diamonds, x="carat", y="price", s=5) sns.rugplot(data=diamonds, x="carat", y="price", lw=1, alpha=.005) # distplot - DEPRECATED: Flexibly plot a univariate distribution of observations. # distplot([a, bins, hist, kde, rug, fit, …])
hue = sort_ensemble.results[rank_num][0].factors[0][:, compi2] thresh = hue > (np.std(hue) * std_thresh) x2 = np.array(xlist)[thresh] y2 = np.array(ylist)[thresh] comp = [] for offcell in zip(x2, y2): for stimcell in zip(x1, y1): comp.append( np.linalg.norm(np.array(offcell) - np.array(stimcell))) all_distances.append(comp) for compi in range(rank_num): sns.ecdfplot(all_distances[compi], label=f'{compi + 1}', ax=ax[0]) # ax[0].legend() ax[0].set_title('Centroid distances: comp n vs all other comps', size=16) ax[0].set_xlabel('distance between centroids\n(pixels)', size=14) ax[0].set_ylabel('Proportion of cells', size=14) # SELF-SELF std_thresh = 1 xlist = [] ylist = [] rank_num = 10 for cell_n in range(len(cell_ids[rank_num])): # x, y = centroids[cell_ids[rank_num][cell_n], :] x, y = centroids[:, cell_ids[rank_num][cell_n] - 1] xlist.append(x)