def plot_colors(): from src.visualization import palplot fig, axs = plt.subplots(1, 6, figsize=(6, 10)) n_per_col = 40 for i, ax in enumerate(axs): pal = cc.glasbey_light[i * n_per_col:(i + 1) * n_per_col] palplot(n_per_col, pal, figsize=(1, 10), ax=ax, start=i * n_per_col)
def plot_colors(): from src.visualization import palplot fig, axs = plt.subplots(1, 6, figsize=(6, 10)) n_per_col = 40 for i, ax in enumerate(axs): pal = cc.glasbey_light[i * n_per_col:(i + 1) * n_per_col] palplot(n_per_col, pal, figsize=(1, 10), ax=ax, start=i * n_per_col) plt.savefig("./maggot_models/notebooks/outs/colors.png", dpi=300, bbox_inches="tight")
def plot_color_labels(full_meta, ax): full_sizes = full_meta.groupby(["merge_class"], sort=False).size() uni_class = full_sizes.index.unique() counts = full_sizes.values count_map = dict(zip(uni_class, counts)) names = [] colors = [] for key, val in count_map.items(): names.append(f"{key} ({count_map[key]})") colors.append(CLASS_COLOR_DICT[key]) colors = colors[::-1] # reverse because of signal flow sorting names = names[::-1] palplot(len(colors), colors, ax=ax) ax.yaxis.set_major_formatter(plt.FixedFormatter(names))
def plot_class_colormap(): from src.visualization import palplot from src.data import load_metagraph mg = load_metagraph("G") uni_class, counts = np.unique(mg["merge_class"], return_counts=True) count_map = dict(zip(uni_class, counts)) names = [] colors = [] for key, val in CLASS_COLOR_DICT.items(): if key in uni_class: names.append(f"{key} ({count_map[key]})") colors.append(val) fig, ax = plt.subplots(1, 1, figsize=(3, 15)) palplot(len(colors), colors, ax=ax) ax.yaxis.set_major_formatter(plt.FixedFormatter(names)) plt.savefig("./maggot_models/notebooks/outs/current_cmap.png", dpi=300, bbox_inches="tight")
# New plot # - Compute signal flow # - Get the centroid of each cluster and project to 1d # - Alternatively, just take the first dimension # - For each cluster plot as a node # output skeletons if SAVESKELS: _, colormap, pal = stashskel(save_name, skeleton_labels, pred_labels, palette="viridis", multiout=True) palplot(k, cmap="viridis") stashfig("palplot-" + save_name) # save dict colormapping filename = (Path("./maggot_models/notebooks/outs") / Path(FNAME) / str("colormap-" + save_name + ".json")) with open(filename, "w") as fout: json.dump(colormap, fout) stashskel(save_name, skeleton_labels, pred_labels, palette="viridis", multiout=False) # %% [markdown]
) def stashobj(obj, name, **kws): saveobj(obj, name, foldername=FNAME, save_on=SAVEOBJS, **kws) # %% [markdown] # # sns.set_context("talk") fig, axs = plt.subplots(1, 4, figsize=(5, 10)) n_per_col = 40 for i, ax in enumerate(axs): pal = cc.glasbey_light[i * n_per_col:(i + 1) * n_per_col] palplot(n_per_col, pal, figsize=(1, 10), ax=ax, start=i * n_per_col) stashfig("glasbey-colors") manual_cmap = { "KC": 0, "KC-1claw": 28, "KC-2claw": 32, "KC-3claw": 92, "KC-4claw": 91, "KC-5claw": 78, "KC-6claw": 61, "APL": 24, "MBIN": 121, "MBIN-DAN": 58, "MBIN-OAN": 5, "MBON": 11,
col_item_order="dend_order", col_tick_pad=[0.5, 1.5], # col_ticks=False, row_meta=path_meta, row_sort_class="cluster", row_item_order="dend_order", row_ticks=True, gridline_kws=dict(linewidth=0.3, color="grey", linestyle="--"), sizes=(2, 2), hue="weight", palette="tab10", ) ax.set_ylabel("Cluster") # fig.suptitle("G") ax = axs[1] palplot(path_len, cmap="tab10", ax=ax) ax.yaxis.tick_right() ax.set_title("Visit\norder") stashfig("path-indcator-GMMoCMDSoPathDist" + basename) # %% [markdown] # ## from src.traverse import to_path_graph import networkx as nx from src.visualization import draw_networkx_nice uni_pred = np.unique(pred)
ax.set_xticks(np.arange(lowest_level + 1)) ax.tick_params(axis="both", which="both", length=0) ax = fig.add_subplot(gs[:, 3]) full_sizes = full_meta.groupby(["merge_class"], sort=False).size() uni_class = full_sizes.index.unique() counts = full_sizes.values count_map = dict(zip(uni_class, counts)) names = [] colors = [] for key, val in count_map.items(): names.append(f"{key} ({count_map[key]})") colors.append(CLASS_COLOR_DICT[key]) colors = colors[::-1] # reverse because of signal flow sorting names = names[::-1] palplot(len(colors), colors, ax=ax) ax.yaxis.set_major_formatter(plt.FixedFormatter(names)) # plt.tight_layout() model = DCSBMEstimator for level in np.arange(lowest_level + 1): ax = fig.add_subplot(gs[:3, level + 4]) adj = binarize(full_mg.adj) _, _, top, _ = adjplot( adj, ax=ax, plot_type="scattermap", sizes=(0.5, 0.5), sort_class=["hemisphere"] + level_names[:level + 1], item_order=["merge_class_sf_order", "merge_class", "sf"], class_order="sf",
col_tick_pad=[0.5, 1.5], # col_ticks=False, row_meta=path_meta, # row_sort_class="cluster", row_item_order="dend_order", row_ticks=True, gridline_kws=dict(linewidth=0.3, color="grey", linestyle="--"), sizes=(2, 2), hue="weight", palette=pal, ) # ax.set_ylabel("Cluster") ax.set_ylabel("Path") top.set_xlabel("Neuron") ax = axs[1] palplot(pal, ax=ax) ax.yaxis.tick_right() ax.set_title("Hop") ax.set_yticklabels(np.arange(1, path_len + 1)) stashfig("path-indcator-dendrosort" + basename) fig, axs = plt.subplots(1, 2, figsize=(30, 20), gridspec_kw=dict(width_ratios=[0.95, 0.02], wspace=0.02)) ax = axs[0] ax, div, top, left = matrixplot( plot_path_indicator_mat, ax=ax,
figsize=(30, 20), gridspec_kw=dict(width_ratios=[0.95, 0.02], wspace=0.02)) pal = sns.color_palette("Set1", n_colors=7) pal = pal[:5] + pal[6:] ax = axs[0] matrixplot( path_indicator_mat, ax=ax, plot_type="scattermap", col_sort_class=["lvl2_labels"], col_class_order="signal_flow", col_meta=meta, col_colors="merge_class", col_item_order=["merge_class", "mean_order"], col_palette=CLASS_COLOR_DICT, col_ticks=True, tick_rot=90, row_sort_class=pred, # row_class_order="size", row_ticks=True, sizes=(1, 1), hue="weight", palette=pal, gridline_kws=dict(linewidth=0.3, color="grey", linestyle="--"), ) ax = axs[1] palplot(pal, cmap="Set1", ax=ax) ax.set_title("Visit order") stashfig("path-indicator-map")