def plot_multi_neuron(neurons, layout, to_save="", scalebar=(200,"$\mu m$"),fig_size=None):
    """Plot mutiple neurons in array manner.
    neurons: neurom.population.Population.
    layout: 1x2 tuple. including the row number and the colunm number.
    to_save: the file to save as. If left empty, not to save.
    fig_size: default: 2x2 inch multiple with layout."""
    if fig_size is None:
        fig_size=(2*layout[0], 2*layout[1])
    fig, axs = plt.subplots(*layout, figsize=fig_size)
    if layout[1]==1 and axs.ndim==1:
        axs=axs[:,np.newaxis]
    elif layout[0]==1 and axs.ndim==1:
        axs=axs[np.newaxis,:]
    for (ind, ax), neuron in zip(np.ndenumerate(np.array(axs)), neurons):
        view.plot_neuron(ax, neuron)
        ax.autoscale()
        ax.set_title("")
        ax.set_xlabel("")
        ax.set_ylabel("")
        ax.set_axis_off()
    left = len(neurons) - layout[0] * layout[1]
    if left<0:
        for ax in axs.flat[left:]:
            ax.set_visible(False)
    plot_unified_scale_grid(fig, axs)
    add_scalebar(axs.flat[-1], scalebar[0], scalebar[1], fig)
    if bool(to_save):
        to_save_figure(to_save)
Exemple #2
0
def test_neuron():
    with get_fig_2d() as (fig, ax):
        view.plot_neuron(ax, fst_neuron)
        nt.ok_(ax.get_title() == fst_neuron.name)
        np.testing.assert_allclose(ax.dataLim.get_points(),
                                   [[-40.32853516, -57.600172],
                                    [64.74726272, 48.51626225], ])

    with get_fig_2d() as (fig, ax):
        nt.assert_raises(AssertionError, view.plot_tree, ax, fst_neuron, plane='wrong')
Exemple #3
0
def test_neuron():
    with get_fig_2d() as (fig, ax):
        view.plot_neuron(ax, fst_neuron)
        ok_(ax.get_title() == fst_neuron.name)
        assert_allclose(ax.dataLim.get_points(),
                                   [[-40.32853516, -57.600172],
                                    [64.74726272, 48.51626225], ])

    with get_fig_2d() as (fig, ax):
        assert_raises(AssertionError, view.plot_tree, ax, fst_neuron, plane='wrong')
Exemple #4
0
def plot(neuron, bbox, subplot, title, **kwargs):
    '''2D neuron plot'''
    ax = plt.subplot(subplot, facecolor='w', aspect='equal')
    xlim = (bbox[0][0], bbox[1][0])
    ylim = (bbox[0][2], bbox[1][2])

    plot_neuron(ax, neuron, **kwargs)
    ax.set_title(title)
    ax.set_aspect('equal', adjustable='box')
    ax.set_xlim(xlim)
    ax.set_ylim(ylim)
Exemple #5
0
def test_neuron(get_fig_2d):
    fig, ax = get_fig_2d
    view.plot_neuron(ax, fst_neuron)
    assert ax.get_title() == fst_neuron.name
    assert_allclose(ax.dataLim.get_points(), [
        [-40.32853516, -57.600172],
        [64.74726272, 48.51626225],
    ])

    with pytest.raises(AssertionError):
        view.plot_tree(ax, fst_neuron, plane='wrong')
def plot_single_neuron(neuron, put_apical_upside=False, to_save=""):
    """Plot a neuron.
    neuron: [neurom.fst._core.FstNeuron] The neuron to plot.
    put_apical_upside: logical. Whether put apical dendrite upside."""
    fig, ax = plt.subplots(subplot_kw={'aspect':'equal'})
    if put_apical_upside:
        neuron=apical_upside(neuron)
    view.plot_neuron(ax, neuron)
    ax.autoscale()
    ax.set_title("")
    ax.set_xlabel(None)
    ax.set_ylabel(None)
    ax.set_axis_off()
    if bool(to_save):
Exemple #7
0
def test_neuron_no_neurites():
    filename = os.path.join(SWC_PATH, 'point_soma.swc')
    with get_fig_2d() as (fig, ax):
        view.plot_neuron(ax, load_neuron(filename))
Exemple #8
0
def test_neuron_no_neurites():
    filename = Path(SWC_PATH, 'point_soma.swc')
    with get_fig_2d() as (fig, ax):
        view.plot_neuron(ax, load_neuron(filename))
=======

>>>>>>> Stashed changes
    """Plot sholl analysis demo figure.
    Display the apical and basal part of a neuron, and concentric circles of sholl analysis.
    Args:
    - neuron: [neurom.fst._core.FstNeuron], a neuron object.
    - step_size: [int], the interval radius of the concentric circles.
    - label_dict: [dict], a dictionary indicate the position of label.
        the keys of dict are the label name, and the values are the (x, y) position.
        Default: {'Apical': (x1, y1), 'Basal': (x2, y2)}, where (x1,y1) and (x2,y2) are computed automatically.
    """
    neuron = apical_upside(neuron)
    fig = plt.figure()
    ax = fig.add_subplot(1,1,1, aspect='equal')
    view.plot_neuron(ax, neuron)

    # draw circles
    center = neuron.soma.center[:2]
    _dist = np.linalg.norm(neuron.points[:,:2]-center, axis=1).max()
    radii = np.arange(step_size, _dist, step_size)
    patches = []
    for rad in radii:
        circle = mpatches.Circle(center, rad, fill=False, edgecolor='dimgray')
        patches.append(circle)
    p = PatchCollection(patches, match_original=True)
    ax.add_collection(p)

    # add labels
    if label_dict is None:
        apical_points = np.concatenate([x.points for x in nm.iter_neurites(neuron, filt=lambda t: t.type==nm.APICAL_DENDRITE)])
Exemple #10
0
def test_neuron_no_neurites(get_fig_2d):
    filename = Path(SWC_PATH, 'point_soma.swc')
    fig, ax = get_fig_2d
    view.plot_neuron(ax, load_neuron(filename))