コード例 #1
0
def plot_fragments(nl, splits, neuron_class=None, scale=8):
    n_col = len(nl)
    fig = plt.figure(figsize=(scale * n_col,
                              scale))  # constrained_layout=True)
    for i, n in enumerate(nl):
        ax = fig.add_subplot(1, n_col, i + 1, projection="3d")
        skid = int(n.skeleton_id)
        if skid in splits.index:
            split_nodes = splits[skid]
            split_locs = pymaid.get_node_location(split_nodes)
            split_locs = split_locs[["x", "y", "z"]].values
            pymaid.plot2d(split_locs,
                          ax=ax,
                          scatter_kws=dict(color="orchid", s=30),
                          method="3d")
            # order of output is axon, dendrite
            fragments = pymaid.cut_neuron(n, split_nodes)
        else:
            fragments = [n]
        n_frag = len(fragments)
        for i, f in enumerate(fragments):
            if n_frag == 1:
                color = colors[2]  # unsplitable
            elif i == n_frag - 1:
                color = colors[1]  # dendrite
            else:
                color = colors[0]  # axon
            f.plot2d(ax=ax, color=color, method="3d")
            title = f"{neuron_class}, {n.neuron_name}, {n.skeleton_id}"
            ax.set_title(title, color="grey")
        set_axes_equal(ax)
    plt.tight_layout()
コード例 #2
0
    # ax = fig.add_subplot(1, 3, 1, projection="3d")
    ax = fig.add_subplot(gs[0, 0], projection="3d")

    pymaid.plot2d(
        ids,
        color=skeleton_color_dict,
        ax=ax,
        connectors=False,
        method="3d",
        autoscale=True,
    )
    ax.azim = -90  # 0 for side view
    ax.elev = 0
    ax.dist = 6
    set_axes_equal(ax)

    # ax = fig.add_subplot(1, 3, 2, projection="3d")
    ax = fig.add_subplot(gs[0, 1], projection="3d")
    pymaid.plot2d(
        ids,
        color=skeleton_color_dict,
        ax=ax,
        connectors=False,
        method="3d",
        autoscale=True,
    )
    ax.azim = 0  # 0 for side view
    ax.elev = 0
    ax.dist = 6
    set_axes_equal(ax)
コード例 #3
0
def set_view_params(ax, azim=-90, elev=0, dist=5):
    ax.azim = azim
    ax.elev = elev
    ax.dist = dist
    set_axes_equal(ax)
コード例 #4
0
def plot_neurons(meta, key=None, label=None, barplot=False):

    if label is not None:
        ids = list(meta[meta[key] == label].index.values)
    else:
        ids = list(meta.index.values)
    ids = [int(i) for i in ids]

    new_ids = []
    for i in ids:
        try:
            pymaid.get_neuron(
                i, raise_missing=True, with_connectors=False, with_tags=False
            )
            new_ids.append(i)
        except:
            print(f"Missing neuron {i}, not plotting it.")

    ids = new_ids
    meta = meta.loc[ids]

    fig = plt.figure(figsize=(30, 10))

    gs = plt.GridSpec(2, 3, figure=fig, wspace=0, hspace=0, height_ratios=[0.8, 0.2])

    skeleton_color_dict = dict(
        zip(meta.index, np.vectorize(CLASS_COLOR_DICT.get)(meta["merge_class"]))
    )

    ax = fig.add_subplot(gs[0, 0], projection="3d")

    pymaid.plot2d(
        ids,
        color=skeleton_color_dict,
        ax=ax,
        connectors=False,
        method="3d",
        autoscale=True,
    )
    ax.azim = -90
    ax.elev = 0
    ax.dist = 5
    set_axes_equal(ax)

    ax = fig.add_subplot(gs[0, 1], projection="3d")
    pymaid.plot2d(
        ids,
        color=skeleton_color_dict,
        ax=ax,
        connectors=False,
        method="3d",
        autoscale=True,
    )
    ax.azim = 0
    ax.elev = 0
    ax.dist = 5
    set_axes_equal(ax)

    ax = fig.add_subplot(gs[0, 2], projection="3d")
    pymaid.plot2d(
        ids,
        color=skeleton_color_dict,
        ax=ax,
        connectors=False,
        method="3d",
        autoscale=True,
    )
    ax.azim = -90
    ax.elev = 90
    ax.dist = 5
    set_axes_equal(ax)

    if barplot:
        ax = fig.add_subplot(gs[1, :])
        temp_meta = meta[meta[key] == label]
        cat = temp_meta[key + "_side"].values
        subcat = temp_meta["merge_class"].values
        stacked_barplot(
            cat,
            subcat,
            ax=ax,
            color_dict=CLASS_COLOR_DICT,
            category_order=np.unique(cat),
        )
        ax.get_legend().remove()

    # fig.suptitle(label)
    return fig, ax