def soma(sm, plane='xy', new_fig=True, subplot=False, hadd=0.0, vadd=0.0, **kwargs): '''Generates a 2d figure of the soma. Parameters ---------- soma: Soma neurom.Soma object ''' treecolor = kwargs.get('treecolor', None) outline = kwargs.get('outline', True) if plane not in ('xy', 'yx', 'xz', 'zx', 'yz', 'zy'): return None, 'No such plane found! Please select one of: xy, xz, yx, yz, zx, zy.' # Initialization of matplotlib figure and axes. fig, ax = _cm.get_figure(new_fig=new_fig, subplot=subplot) # Definition of the tree color depending on the tree type. treecolor = _cm.get_color(treecolor, tree_type='soma') # Plot the outline of the soma as a circle, is outline is selected. if not outline: soma_circle = _cm.plt.Circle(sm.get_center() + [hadd, vadd, 0.0], sm.get_diameter() / 2., color=treecolor, alpha=_get_default('alpha', **kwargs)) ax.add_artist(soma_circle) else: horz = getattr(sm, plane[0]) + hadd vert = getattr(sm, plane[1]) + vadd horz = _np.append( horz, horz[0]) + hadd # To close the loop for a soma viewer. vert = _np.append( vert, vert[0]) + vadd # To close the loop for a soma viewer. _cm.plt.plot(horz, vert, color=treecolor, alpha=_get_default('alpha', **kwargs), linewidth=_get_default('linewidth', **kwargs)) kwargs['title'] = kwargs.get('title', 'Soma view') kwargs['xlabel'] = kwargs.get('xlabel', plane[0]) kwargs['ylabel'] = kwargs.get('ylabel', plane[1]) return _cm.plot_style(fig=fig, ax=ax, **kwargs)
def soma3d(sm, new_fig=True, new_axes=True, subplot=False, **kwargs): '''Generates a 3d figure of the soma. Parameters ---------- soma: Soma neurom.Soma object ''' treecolor = kwargs.get('treecolor', None) # Initialization of matplotlib figure and axes. fig, ax = _cm.get_figure(new_fig=new_fig, new_axes=new_axes, subplot=subplot, params={'projection': '3d'}) # Definition of the tree color depending on the tree type. treecolor = _cm.get_color(treecolor, tree_type='soma') center = sm.get_center() xs = center[0] ys = center[1] zs = center[2] # Plot the soma as a circle. fig, ax = _cm.plot_sphere(fig, ax, center=[xs, ys, zs], radius=sm.get_diameter(), color=treecolor, alpha=_get_default('alpha', **kwargs)) kwargs['title'] = kwargs.get('title', 'Soma view') kwargs['xlabel'] = kwargs.get('xlabel', 'X') kwargs['ylabel'] = kwargs.get('ylabel', 'Y') kwargs['zlabel'] = kwargs.get('zlabel', 'Z') return _cm.plot_style(fig=fig, ax=ax, **kwargs)
def tree(tr, plane='xy', new_fig=True, subplot=False, hadd=0.0, vadd=0.0, **kwargs): '''Generates a 2d figure of the tree. Parameters ---------- tr: Tree neurom.Tree object ''' if plane not in ('xy', 'yx', 'xz', 'zx', 'yz', 'zy'): return None, 'No such plane found! Please select one of: xy, xz, yx, yz, zx, zy.' # Initialization of matplotlib figure and axes. fig, ax = _cm.get_figure(new_fig=new_fig, subplot=subplot) # Data needed for the viewer: x,y,z,r bounding_box = tr.get_bounding_box() def _seg_2d(seg, x_add=0.0, y_add=0.0): """2d coordinates required for the plotting of a segment""" horz = _utils.term_dict[plane[0]] vert = _utils.term_dict[plane[1]] horz1 = seg[0][horz] + x_add horz2 = seg[1][horz] + x_add vert1 = seg[0][vert] + y_add vert2 = seg[1][vert] + y_add return ((horz1, vert1), (horz2, vert2)) segs = [_seg_2d(seg, hadd, vadd) for seg in tr.get_segments()] linewidth = _get_default('linewidth', **kwargs) # Definition of the linewidth according to diameter, if diameter is True. if _get_default('diameter', **kwargs): scale = _get_default('diameter_scale', **kwargs) linewidth = [d * scale for d in tr.d] if tr.get_type() not in _utils.tree_type: treecolor = 'black' else: treecolor = _cm.get_color(_get_default('treecolor', **kwargs), _utils.tree_type[tr.get_type()]) # Plot the collection of lines. collection = _LC(segs, color=treecolor, linewidth=linewidth, alpha=_get_default('alpha', **kwargs)) ax.add_collection(collection) kwargs['title'] = kwargs.get('title', 'Tree view') kwargs['xlabel'] = kwargs.get('xlabel', plane[0]) kwargs['ylabel'] = kwargs.get('ylabel', plane[1]) white_space = _get_default('white_space', **kwargs) kwargs['xlim'] = kwargs.get('xlim', [ bounding_box[0][_utils.term_dict[plane[0]]] - white_space, bounding_box[1][_utils.term_dict[plane[0]]] + white_space ]) kwargs['ylim'] = kwargs.get('ylim', [ bounding_box[0][_utils.term_dict[plane[1]]] - white_space, bounding_box[1][_utils.term_dict[plane[1]]] + white_space ]) return _cm.plot_style(fig=fig, ax=ax, **kwargs)
def trunk3d(tr, new_fig=True, new_axes=True, subplot=False, N=10, **kwargs): '''Generates a figure of the trunk in 3d. Parameters ---------- tr: Tree neurom.Tree object ''' # pylint: disable=import-outside-toplevel from mpl_toolkits.mplot3d.art3d import Line3DCollection # Initialization of matplotlib figure and axes. fig, ax = _cm.get_figure(new_fig=new_fig, new_axes=new_axes, subplot=subplot, params={'projection': '3d'}) def _seg_3d(seg): """3d coordinates needed for the plotting of a segment""" horz = _utils.term_dict['x'] vert = _utils.term_dict['y'] depth = _utils.term_dict['z'] horz1 = seg[0][horz] horz2 = seg[1][horz] vert1 = seg[0][vert] vert2 = seg[1][vert] depth1 = seg[0][depth] depth2 = seg[1][depth] return ((horz1, vert1, depth1), (horz2, vert2, depth2)) if len(tr.get_segments()) < N: N = len(tr.get_segments()) segs = [_seg_3d(seg) for seg in tr.get_segments()[:N]] linewidth = _get_default('linewidth', **kwargs) # Definition of the linewidth according to diameter, if diameter is True. if _get_default('diameter', **kwargs): scale = _get_default('diameter_scale', **kwargs) linewidth = [d * scale for d in tr.d] treecolor = _cm.get_color(_get_default('treecolor', **kwargs), _utils.tree_type[tr.get_type()]) # Plot the collection of lines. collection = Line3DCollection(segs, color=treecolor, linewidth=linewidth, alpha=_get_default('alpha', **kwargs)) ax.add_collection3d(collection) kwargs['title'] = kwargs.get('title', 'Tree 3d-view') kwargs['xlabel'] = kwargs.get('xlabel', 'X') kwargs['ylabel'] = kwargs.get('ylabel', 'Y') kwargs['zlabel'] = kwargs.get('zlabel', 'Z') return _cm.plot_style(fig=fig, ax=ax, **kwargs)