Plots the 2d histogram of the center
       coordinates of segments in the selected plane
       and superimposes the view of the first neurite of the collection.
979971
def plot_neuron_on_density(population, # pylint: disable=too-many-arguments
                           bins=100, new_fig=True, subplot=111, levels=None, plane='xy',
                           colorlabel='Nodes per unit area', labelfontsize=16,
                           color_map='Reds', no_colorbar=False, threshold=0.01,
                           neurite_type=NeuriteType.basal_dendrite, **kwargs):
    '''
    '''
    _, ax = common.get_figure(new_fig=new_fig)

    view.plot_tree(ax, population.neurites[0])

    return plot_density(population, plane=plane, bins=bins, new_fig=False, subplot=subplot,
                        colorlabel=colorlabel, labelfontsize=labelfontsize, levels=levels,
                        color_map=color_map, no_colorbar=no_colorbar, threshold=threshold,
                        neurite_type=neurite_type, **kwargs)
720065
def plot(self, axis, ith_plot, total_plots, limits):
        
        print(self.plot_type_str.upper() + " plot")
        print("%5s %9s  %s" % ("id", " #points", "group"))

        for idx, group in enumerate(self.groups):
            print("%5s %9s  %s" % (idx + 1, len(self.groups[group]), group))

        print('')

        datasets = []
        colors = []
        minx = np.inf
        maxx = -np.inf

        for idx, group in enumerate(self.groups):
            x = date2num([logevent.datetime
                          for logevent in self.groups[group]])
            minx = min(minx, min(x))
            maxx = max(maxx, max(x))
            datasets.append(x)
            color, marker = self.color_map(group)
            colors.append(color)

        if total_plots > 1:
            # if more than one plot, move histogram to twin axis on the right
            twin_axis = axis.twinx()
            twin_axis.set_ylabel(self.ylabel)
            axis.set_zorder(twin_axis.get_zorder() + 1)  # put ax ahead of ax2
            axis.patch.set_visible(False)  # hide the 'canvas'
            axis = twin_axis

        n_bins = max(1, int((maxx - minx) * 24. * 60. * 60. / self.bucketsize))
        if n_bins > 1000:
            # warning for too many buckets
            print("warning: %i buckets, will take a while to render. "
                  "consider increasing --bucketsize." % n_bins)

        n, bins, artists = axis.hist(datasets, bins=n_bins, align='mid',
                                     log=self.logscale,
                                     histtype="barstacked"
                                     if self.barstacked else "bar",
                                     color=colors, edgecolor="none",
                                     linewidth=0, alpha=0.8, picker=True,
                                     label=map(str, self.groups.keys()))

        # scale current y-axis to match min and max values
        axis.set_ylim(np.min(n), np.max(n))

        # add meta-data for picking
        if len(self.groups) > 1:
            for g, group in enumerate(self.groups.keys()):
                for i in range(len(artists[g])):
                    artists[g][i]._mt_plot_type = self
                    artists[g][i]._mt_group = group
                    artists[g][i]._mt_n = n[g][i]
                    if self.barstacked:
                        artists[g][i]._mt_n -= (n[g - 1][i] if g > 0 else 0)

                    artists[g][i]._mt_bin = bins[i]
        else:
            for i in range(len(artists)):
                artists[i]._mt_plot_type = self
                artists[i]._mt_group = group
                artists[i]._mt_n = n[i]
                artists[i]._mt_bin = bins[i]

        return artists
920634
def plot_plane(where="back", texture=None):
    
    fig = gcf()
    xmin, xmax = fig.xlim
    ymin, ymax = fig.ylim
    zmin, zmax = fig.zlim
    if where == "back":
        x = [xmin, xmax, xmax, xmin]
        y = [ymin, ymin, ymax, ymax]
        z = [zmin, zmin, zmin, zmin]
    if where == "front":
        x = [xmin, xmax, xmax, xmin][::-1]
        y = [ymin, ymin, ymax, ymax]
        z = [zmax, zmax, zmax, zmax]
    if where == "left":
        x = [xmin, xmin, xmin, xmin]
        y = [ymin, ymin, ymax, ymax]
        z = [zmin, zmax, zmax, zmin]
    if where == "right":
        x = [xmax, xmax, xmax, xmax]
        y = [ymin, ymin, ymax, ymax]
        z = [zmin, zmax, zmax, zmin][::-1]
    if where == "top":
        x = [xmin, xmax, xmax, xmin]
        y = [ymax, ymax, ymax, ymax]
        z = [zmax, zmax, zmin, zmin]
    if where == "bottom":
        x = [xmax, xmin, xmin, xmax]
        y = [ymin, ymin, ymin, ymin]
        z = [zmin, zmin, zmax, zmax]
    triangles = [(0, 1, 2), (0, 2, 3)]
    u = v = None
    if texture is not None:
        u = [0.0, 1.0, 1.0, 0.0]
        v = [0.0, 0.0, 1.0, 1.0]
    mesh = plot_trisurf(x, y, z, triangles, texture=texture, u=u, v=v)
    return mesh
654831
def _render_dendrogram(dnd, ax, displacement):
    ''''''
    # set of unique colors that reflect the set of types of the neurites
    colors = set()

    for n, (indices, ctype) in enumerate(zip(dnd.groups, dnd.types)):

        # slice rectangles array for the current neurite
        group = dnd.data[indices[0]:indices[1]]

        if n > 0:
            # displace the neurites by half of their maximum x dimension
            # plus half of the previous neurite's maxmimum x dimension
            displacement += 0.5 * (dnd.dims[n - 1][0] + dnd.dims[n][0])

        # arrange the trees without overlapping with each other
        group += (displacement, 0.)

        # create the polygonal collection of the dendrogram
        # segments
        _generate_collection(group, ax, ctype, colors)

    soma_square = dnd.soma

    if soma_square is not None:

        _generate_collection((soma_square + (displacement / 2., 0.),), ax, NeuriteType.soma, colors)
        ax.plot((displacement / 2., displacement), (0., 0.), color='k')
        ax.plot((0., displacement / 2.), (0., 0.), color='k')

    return displacement
740904
def network_sketch(ax, highlight=None, labels=True, yscaling=1.):    
    '''
    
    '''

    name_to_id_mapping={'L6E':(0,0),
                        'L6I':(0,1),
                        'L5E':(1,0),
                        'L5I':(1,1),
                        'L4E':(2,0),
                        'L4I':(2,1),
                        'L23E':(3,0),
                        'L23I':(3,1)
    } 
    
    showgrid=False  ## switch on/off grid

    ## sketch parameters
    layer_x=0.1                            ## x position of left boundary of cortex layers
    layer6_y=0.2*yscaling                           ## y position of lower boundary of layer 6
    layer_width=0.65                       ## width of cortex layers
    layer_height=0.21*yscaling                      ## height of cortex layers
    layer_colors=['0.9','0.8','0.9','0.8'] ## layer colors
    c_pop_size=0.15                        ## cortex population size
    c_pop_dist=0.17                        ## distance between cortex populations
    t_pop_size=0.15                        ## thalamus population size
    t_pop_y=0.0                         ## y position of lower thalamus boundary
    axon_cell_sep=0.04                     ## distance between axons and popualations
    cc_input_y=0.6*yscaling                        ## y position of cortico-cortical synapses (relative to cortex population)
    tc_input_y=0.4*yscaling                         ## y position of thalamo-cortical synapses (relative to cortex population)

    exc_clr = 'k' if analysis_params.bw else analysis_params.colorE                            ## color of excitatory axons/synapses
    inh_clr = 'gray' if analysis_params.bw else analysis_params.colorI                            ## color of inhibitory axons/synapses

    lw_pop=0.5                              ## linewidth for populations
    lw_axons=0.4                           ## linewidth for axons

    arrow_size=0.013                       ## arrow size
    conn_radius=0.005                      ## radius of connector marker

    legend_length=0.07                     ## length of legend arrows
    
    colors = phlp.get_colors(8)[::-1]            ## colors of each population

    fontdict1={'fontsize': 6, ## population name 
              'weight':'normal',
              'horizontalalignment':'center',
              'verticalalignment':'center'}

    fontdict2={'fontsize': 6, ## cortico-cortical input
              'weight':'normal',
              'horizontalalignment':'center',
              'verticalalignment':'center'}

    fontdict3={'fontsize': 6, ## legend 
              'weight':'normal',
              'horizontalalignment':'left',
              'verticalalignment':'center'}

    ######################################################################################

    def draw_box(ax,pos,lw=1.,ls='solid',eclr='k',fclr='w',zorder=0, clip_on=False,
                 boxstyle=patches.BoxStyle("Round", pad=0.0), padadjust=0.):
        '''Draws a rectangle.'''    
        rect = patches.FancyBboxPatch((pos[0]+padadjust, pos[1]+padadjust),
            pos[2]-2*padadjust, pos[3]-2*padadjust, ec=eclr, fc=fclr,
            lw=lw, ls=ls, zorder=zorder, clip_on=clip_on,
            boxstyle=boxstyle)
        ax.add_patch(rect)

    def draw_circle(ax,xy,radius,lw=1.,ls='solid',eclr='k',fclr='w',zorder=0):
        '''Draws a circle.'''    
        circ = plt.Circle((xy[0],xy[1]),radius=radius, ec=eclr,fc=fclr,lw=lw,ls=ls,zorder=zorder)
        ax.add_patch(circ)

    def put_text(ax,xy,txt,clr,fontdict,zorder=10):
        '''Puts text to a specific position.'''
        ax.text(xy[0],xy[1],txt,fontdict=fontdict,color=clr,zorder=zorder)

    def draw_line(ax,path,lw=1.,ls='solid',lclr='k',zorder=0):
        '''Draws a path.'''
        #pth = path.Path(np.array(path))
        pth = Path(np.array(path))        
        patch = patches.PathPatch(pth, fill=False, lw=lw,ls=ls,ec=lclr,fc=lclr,zorder=zorder)
        ax.add_patch(patch)

    def draw_arrow(ax,path,lw=1.0,ls='solid',lclr='k',arrow_size=0.025,zorder=0):
        '''Draws a path with an arrow at the end. '''
        x=path[-2][0]
        y=path[-2][1]
        dx=path[-1][0]-path[-2][0]
        dy=path[-1][1]-path[-2][1]

        D=np.array([dx,dy])
        D=D/np.sqrt(D[0]**2+D[1]**2)
        path2=np.array(path).copy()
        path2[-1,:]=path2[-1,:]-arrow_size*D

        pth = Path(np.array(path2))
        patch = patches.PathPatch(pth, fill=False, lw=lw,ls=ls,ec=lclr,fc=lclr,zorder=zorder)
        ax.add_patch(patch)

        arr=patches.FancyArrow(\
            x,y,dx,dy,\
                length_includes_head=True,width=0.0,head_width=arrow_size,\
                overhang=0.2,ec=lclr,fc=lclr,linewidth=0)
        ax.add_patch(arr)


    ##################################################
    ## populations

    ## cortex
    layer_pos=[]
    c_pop_pos=[]
    for i in xrange(4):

        ## cortex layers
        layer_pos+=[[layer_x,layer6_y+i*layer_height*yscaling,layer_width,layer_height]] ## layer positions
        draw_box(ax,layer_pos[i],lw=0.,fclr=layer_colors[i],zorder=0)

        ## cortex populations
        l_margin=(layer_width-2.*c_pop_size-c_pop_dist)/2.
        b_margin=(layer_height-c_pop_size)/2.

        ## positions of cortex populations
        c_pop_pos+=[[ [layer_pos[i][0] + l_margin,
                       layer_pos[i][1] + b_margin,
                       c_pop_size, c_pop_size], ## E
                      [layer_pos[i][0] + l_margin + c_pop_size + c_pop_dist,
                       layer_pos[i][1] + b_margin,
                       c_pop_size, c_pop_size]  ]] ## I

        #draw_box(ax,c_pop_pos[i][0],lw=lw_pop,eclr='k',fclr='w',zorder=2) ## E
        #draw_box(ax,c_pop_pos[i][1],lw=lw_pop,eclr='k',fclr='w',zorder=2) ## I    
        draw_box(ax,c_pop_pos[i][0],lw=lw_pop,eclr='k',fclr=colors[i*2+1],zorder=2,
                 boxstyle=patches.BoxStyle("Round", pad=0.02), padadjust=0.02) ## E
        draw_box(ax,c_pop_pos[i][1],lw=lw_pop,eclr='k',fclr=colors[i*2],zorder=2,
                 boxstyle=patches.BoxStyle("Round", pad=0.02), padadjust=0.02) ## I    


    ## thalamus
    c_center_x=layer_x+layer_width/2. ## x position of cortex center
    t_pos=[c_center_x-t_pop_size/2.,t_pop_y*yscaling,t_pop_size,t_pop_size] ## thalamus position
    #draw_box(ax,t_pos,lw=lw_pop,eclr='k',fclr='w',zorder=2) ## Th
    draw_box(ax,t_pos,lw=lw_pop,eclr='k',fclr='k',zorder=2,
             boxstyle=patches.BoxStyle("Round", pad=0.02), padadjust=0.02) ## Th

    ##################################################
    ## intracortical axons

    axon_x_dist=(c_pop_dist-2.*axon_cell_sep)/7.
    assert(axon_x_dist>0.)
    axon_y_dist=c_pop_size/9.#*yscaling
    c_axon_x=[]
    c_axon_y=[]

    # x positions of vertical intracortical axons
    for i in xrange(4): # pre layer
        exc=c_pop_pos[i][0][0]+c_pop_size+axon_cell_sep+i*axon_x_dist ## E
        inh=exc+4.*axon_x_dist ## I
        c_axon_x+=[[exc,inh]]

    # y positions of horizontal intracortical axons
    for i in xrange(4): ## post layer
        c_axon_y+=[[]]
        for j in xrange(4): ## pre layer
            exc=c_pop_pos[i][0][1]+(j+1.)*axon_y_dist ## E
            inh=c_pop_pos[i][0][1]+c_pop_size-(j+1.)*axon_y_dist ## I        
            c_axon_y[i]+=[[exc,inh]]

    ## vertical intracortical axons
    for i in xrange(4):
        draw_line(ax,[[c_axon_x[i][0],c_axon_y[0][i][0]],[c_axon_x[i][0],c_axon_y[-1][i][0]]],lw=lw_axons,ls='solid',lclr=exc_clr,zorder=1)
        draw_line(ax,[[c_axon_x[i][1],c_axon_y[0][i][1]],[c_axon_x[i][1],c_axon_y[-1][i][1]]],lw=lw_axons,ls='solid',lclr=inh_clr,zorder=0)

    ## horizontal intracortical axons
    for i in xrange(4): ## post layer
        for j in xrange(4): ## pre layer
            path=[[c_axon_x[j][0],c_axon_y[i][j][0]],[c_pop_pos[i][0][0]+c_pop_size,c_axon_y[i][j][0]]]        
            draw_arrow(ax,path,lw=lw_axons,ls='solid',lclr=exc_clr,arrow_size=arrow_size,zorder=1)

            path=[[c_axon_x[j][0],c_axon_y[i][j][0]],[c_pop_pos[i][1][0],c_axon_y[i][j][0]]]        
            draw_arrow(ax,path,lw=lw_axons,ls='solid',lclr=exc_clr,arrow_size=arrow_size,zorder=1)

            path=[[c_axon_x[j][1],c_axon_y[i][j][1]],[c_pop_pos[i][1][0],c_axon_y[i][j][1]]]
            draw_arrow(ax,path,lw=lw_axons,ls='solid',lclr=inh_clr,arrow_size=arrow_size,zorder=0)

            path=[[c_axon_x[j][1],c_axon_y[i][j][1]],[c_pop_pos[i][0][0]+c_pop_size,c_axon_y[i][j][1]]]
            draw_arrow(ax,path,lw=lw_axons,ls='solid',lclr=inh_clr,arrow_size=arrow_size,zorder=0)

            ## connector markers
            draw_circle(ax,[c_axon_x[j][0],c_axon_y[i][j][0]],conn_radius,lw=0,fclr=exc_clr,zorder=0)
            draw_circle(ax,[c_axon_x[j][1],c_axon_y[i][j][1]],conn_radius,lw=0,fclr=inh_clr,zorder=0)        

    ## cell outputs
    for i in xrange(4):

        path=[[c_pop_pos[i][0][0]+c_pop_size/2.,c_pop_pos[i][0][1]],
              [c_pop_pos[i][0][0]+c_pop_size/2.,c_pop_pos[i][0][1]-axon_y_dist],
              [c_axon_x[i][0],c_pop_pos[i][0][1]-axon_y_dist]]
        draw_line(ax,path,lw=lw_axons,ls='solid',lclr=exc_clr,zorder=1)  ## excitatory
        draw_circle(ax,path[-1],conn_radius,lw=0,fclr=exc_clr,zorder=0) ## connector

        path=[[c_pop_pos[i][1][0]+c_pop_size/2.,c_pop_pos[i][1][1]],
              [c_pop_pos[i][1][0]+c_pop_size/2.,c_pop_pos[i][1][1]-axon_y_dist],
              [c_axon_x[-1-i][1],c_pop_pos[i][1][1]-axon_y_dist]]
        draw_line(ax,path,lw=lw_axons,ls='solid',lclr=inh_clr,zorder=1)  ## inhibitory
        draw_circle(ax,path[-1],conn_radius,lw=0,fclr=inh_clr,zorder=0) ## connector

    ## remaining first segments for L6
    path=[[c_axon_x[0][0],c_pop_pos[0][0][1]-axon_y_dist],[c_axon_x[0][0],c_axon_y[0][0][0]]]        
    draw_line(ax,path,lw=lw_axons,ls='solid',lclr=exc_clr,zorder=0)        
    path=[[c_axon_x[-1][1],c_pop_pos[0][1][1]-axon_y_dist],[c_axon_x[-1][1],c_axon_y[0][0][1]]]        
    draw_line(ax,path,lw=lw_axons,ls='solid',lclr=inh_clr,zorder=0)        

    ##################################################
    ## cortico-cortical axons

    ## horizontal branch in L1
    path=[[0.,c_pop_pos[-1][0][1]+c_pop_size+axon_cell_sep],
          [c_pop_pos[-1][1][0]+c_pop_size+axon_cell_sep,c_pop_pos[-1][0][1]+c_pop_size+axon_cell_sep]]
    draw_line(ax,path,lw=lw_axons,ls='solid',lclr=exc_clr,zorder=1)

    ## vertical branches
    path=[[c_pop_pos[-1][0][0]-axon_cell_sep,c_pop_pos[-1][0][1]+c_pop_size+axon_cell_sep],
          [c_pop_pos[-1][0][0]-axon_cell_sep,c_pop_pos[0][0][1]+cc_input_y*c_pop_size]]
    draw_line(ax,path,lw=lw_axons,ls='solid',lclr=exc_clr,zorder=1) ## cc input to exc pop
    draw_circle(ax,path[0],conn_radius,lw=0,fclr=exc_clr,zorder=0) ## connector
    path=[[c_pop_pos[-1][1][0]+c_pop_size+axon_cell_sep,c_pop_pos[-1][0][1]+c_pop_size+axon_cell_sep],
          [c_pop_pos[-1][1][0]+c_pop_size+axon_cell_sep,c_pop_pos[0][0][1]+cc_input_y*c_pop_size]]
    draw_line(ax,path,lw=lw_axons,ls='solid',lclr=exc_clr,zorder=1) ## cc input to inh pop
    draw_circle(ax,path[0],conn_radius,lw=0,fclr=exc_clr,zorder=0) ## connector

    ## horizontal branches (arrows)
    for i in xrange(4):
        ## cc input to excitatory populations
        path=[[c_pop_pos[-1][0][0]-axon_cell_sep,c_pop_pos[i][0][1]+cc_input_y*c_pop_size],
              [c_pop_pos[-1][0][0],c_pop_pos[i][0][1]+cc_input_y*c_pop_size],]
        draw_arrow(ax,path,lw=lw_axons,ls='solid',lclr=exc_clr,arrow_size=arrow_size,zorder=0)
        draw_circle(ax,path[0],conn_radius,lw=0,fclr=exc_clr,zorder=0) ## connector

        ## cc input to inhibitory populations
        path=[[c_pop_pos[-1][1][0]+c_pop_size+axon_cell_sep,c_pop_pos[i][0][1]+cc_input_y*c_pop_size],
              [c_pop_pos[-1][1][0]+c_pop_size,c_pop_pos[i][0][1]+cc_input_y*c_pop_size]]
        draw_arrow(ax,path,lw=lw_axons,ls='solid',lclr=exc_clr,arrow_size=arrow_size,zorder=0)
        draw_circle(ax,path[0],conn_radius,lw=0,fclr=exc_clr,zorder=0) ## connector

    ##################################################
    ## thalamo-cortical axons

    path=[[t_pos[0]+t_pop_size/2.,t_pos[1]+t_pop_size],
          [t_pos[0]+t_pop_size/2.,t_pos[1]+t_pop_size+axon_y_dist]]
    draw_line(ax,path,lw=lw_axons,ls='solid',lclr=exc_clr,zorder=1) ## thalamic output
    draw_circle(ax,path[-1],conn_radius,lw=0,fclr=exc_clr,zorder=0) ## connector

    path=[[c_pop_pos[0][0][0]-(axon_cell_sep+axon_y_dist),t_pos[1]+t_pop_size+axon_y_dist],
          [c_pop_pos[0][1][0]+c_pop_size+(axon_cell_sep+axon_y_dist),t_pos[1]+t_pop_size+axon_y_dist]]
    draw_line(ax,path,lw=lw_axons,ls='solid',lclr=exc_clr,zorder=1) ## horizontal branch

    path=[[c_pop_pos[0][0][0]-(axon_cell_sep+axon_y_dist),t_pos[1]+t_pop_size+axon_y_dist],
          [c_pop_pos[0][0][0]-(axon_cell_sep+axon_y_dist),c_pop_pos[2][0][1]+tc_input_y*c_pop_size]]
    draw_line(ax,path,lw=lw_axons,ls='solid',lclr=exc_clr,zorder=1) ## left vertical branch

    path=[[c_pop_pos[0][1][0]+c_pop_size+(axon_cell_sep+axon_y_dist),t_pos[1]+t_pop_size+axon_y_dist],
          [c_pop_pos[0][1][0]+c_pop_size+(axon_cell_sep+axon_y_dist),c_pop_pos[2][0][1]+tc_input_y*c_pop_size]]
    draw_line(ax,path,lw=lw_axons,ls='solid',lclr=exc_clr,zorder=1) ## right vertical branch

    path=[[c_pop_pos[0][0][0]-(axon_cell_sep+axon_y_dist),c_pop_pos[2][0][1]+tc_input_y*c_pop_size],
          [c_pop_pos[0][0][0],c_pop_pos[2][0][1]+tc_input_y*c_pop_size],]
    draw_arrow(ax,path,lw=lw_axons,ls='solid',lclr=exc_clr,arrow_size=arrow_size,zorder=1) ## Th -> L4E synapses (arrows)
    draw_circle(ax,path[0],conn_radius,lw=0,fclr=exc_clr,zorder=0) ## connector

    path=[[c_pop_pos[0][0][0]-(axon_cell_sep+axon_y_dist),c_pop_pos[0][0][1]+tc_input_y*c_pop_size],
          [c_pop_pos[0][0][0],c_pop_pos[0][0][1]+tc_input_y*c_pop_size],]
    draw_arrow(ax,path,lw=lw_axons,ls='solid',lclr=exc_clr,arrow_size=arrow_size,zorder=1) ## Th -> L6E synapses (arrows)
    draw_circle(ax,path[0],conn_radius,lw=0,fclr=exc_clr,zorder=0) ## connector

    path=[[c_pop_pos[0][1][0]+c_pop_size+(axon_cell_sep+axon_y_dist),c_pop_pos[2][0][1]+tc_input_y*c_pop_size],
          [c_pop_pos[0][1][0]+c_pop_size,c_pop_pos[2][0][1]+tc_input_y*c_pop_size],]
    draw_arrow(ax,path,lw=lw_axons,ls='solid',lclr=exc_clr,arrow_size=arrow_size,zorder=1) ## Th -> L4I synapses (arrows)
    draw_circle(ax,path[0],conn_radius,lw=0,fclr=exc_clr,zorder=0) ## connector

    path=[[c_pop_pos[0][1][0]+c_pop_size+(axon_cell_sep+axon_y_dist),c_pop_pos[0][0][1]+tc_input_y*c_pop_size],
          [c_pop_pos[0][1][0]+c_pop_size,c_pop_pos[0][0][1]+tc_input_y*c_pop_size],]
    draw_arrow(ax,path,lw=lw_axons,ls='solid',lclr=exc_clr,arrow_size=arrow_size,zorder=1) ## Th -> L6I synapses (arrows)
    draw_circle(ax,path[0],conn_radius,lw=0,fclr=exc_clr,zorder=0) ## connector

    if labels:
        ##################################################
        ## legend
        legend_x=[t_pos[0]+t_pop_size+axon_cell_sep,t_pos[0]+t_pop_size+axon_cell_sep+legend_length]
        legend_y=[t_pos[1],(t_pos[1]+2*t_pop_size/3)]
        draw_arrow(ax,[[legend_x[0],legend_y[1]],[legend_x[1],legend_y[1]]],lw=lw_axons,ls='solid',lclr=exc_clr,arrow_size=arrow_size,zorder=1)
        draw_arrow(ax,[[legend_x[0],legend_y[0]],[legend_x[1],legend_y[0]]],lw=lw_axons,ls='solid',lclr=inh_clr,arrow_size=arrow_size,zorder=1)

        ##################################################
        ## population names

        put_text(ax,[t_pos[0]+t_pop_size/2.,(t_pos[1]+t_pop_size/2.)],r'TC','w',fontdict1)

        put_text(ax,[c_pop_pos[0][0][0]+c_pop_size/2.,c_pop_pos[0][0][1]+c_pop_size/2.],r'L6E','w' if analysis_params.bw else 'k',fontdict1)
        put_text(ax,[c_pop_pos[0][1][0]+c_pop_size/2.,c_pop_pos[0][1][1]+c_pop_size/2.],r'L6I','w' if analysis_params.bw else 'k',fontdict1)
        
        put_text(ax,[c_pop_pos[1][0][0]+c_pop_size/2.,c_pop_pos[1][0][1]+c_pop_size/2.],r'L5E','w' if analysis_params.bw else 'k',fontdict1)
        put_text(ax,[c_pop_pos[1][1][0]+c_pop_size/2.,c_pop_pos[1][1][1]+c_pop_size/2.],r'L5I','w' if analysis_params.bw else 'k',fontdict1)
        
        put_text(ax,[c_pop_pos[2][0][0]+c_pop_size/2.,c_pop_pos[2][0][1]+c_pop_size/2.],r'L4E','w' if analysis_params.bw else 'k',fontdict1)
        put_text(ax,[c_pop_pos[2][1][0]+c_pop_size/2.,c_pop_pos[2][1][1]+c_pop_size/2.],r'L4I','w' if analysis_params.bw else 'k',fontdict1)
    
        put_text(ax,[c_pop_pos[3][0][0]+c_pop_size/2.,c_pop_pos[3][0][1]+c_pop_size/2.],r'L23E','w' if analysis_params.bw else 'k',fontdict1)
        put_text(ax,[c_pop_pos[3][1][0]+c_pop_size/2.,c_pop_pos[3][1][1]+c_pop_size/2.],r'L23I','w' if analysis_params.bw else 'k',fontdict1)
        
        put_text(ax,[c_pop_pos[-1][0][0],
                 c_pop_pos[-1][0][1]+c_pop_size+1.7*axon_cell_sep + 0.01],
                 r'cortico-cortical input','k',fontdict2)

        put_text(ax,[legend_x[1]+axon_y_dist,legend_y[1]],r'excitatory','k',fontdict3)
        put_text(ax,[legend_x[1]+axon_y_dist,legend_y[0]],r'inhibitory','k',fontdict3)

        ##################################################
        ## layer names

        put_text(ax,[0.2*c_pop_pos[0][0][0],c_pop_pos[0][1][1]+c_pop_size/2.],r'L6','k',fontdict1)
        put_text(ax,[0.2*c_pop_pos[1][0][0],c_pop_pos[1][1][1]+c_pop_size/2.],r'L5','k',fontdict1)
        put_text(ax,[0.2*c_pop_pos[2][0][0],c_pop_pos[2][1][1]+c_pop_size/2.],r'L4','k',fontdict1)
        put_text(ax,[0.2*c_pop_pos[3][0][0],c_pop_pos[3][1][1]+c_pop_size/2.],r'L2/3','k',fontdict1)
        
                
    if highlight is not None:
        ids = name_to_id_mapping[highlight]
        fontdict1['fontsize']=4
        put_text(ax,[c_pop_pos[ids[0]][ids[1]][0]+c_pop_size/2.,c_pop_pos[ids[0]][ids[1]][1]+c_pop_size/2.],highlight,'k',fontdict1)

    ax.xaxis.set_ticks([])
    ax.yaxis.set_ticks([])
    ax.axis(ax.axis('equal'))
    
    return ax
435868
def plot_init(fignum, w, h):
    
    global fig_x_pos, fig_y_pos, plt_num
    dpi = 80
    if isServer:
        dpi = 240
    # plt.ion()
    plt_num += 1
    fig = plt.figure(num=fignum, figsize=(w, h), dpi=dpi)
    if (not isServer) and (not set_env.IS_NOTEBOOK):
        plt.get_current_fig_manager().show()
        # plt.get_current_fig_manager().window.wm_geometry('+%d+%d' %
        # (fig_x_pos,fig_y_pos)) # this only works with matplotlib.use('TKAgg')
        fig_x_pos = fig_x_pos + dpi * (w) + 25
        if plt_num == 3:
            plt_num = 0
            fig_x_pos = 25
            fig_y_pos = fig_y_pos + dpi * (h) + 25
        plt.figtext(.02, .01, version_num)
# plt.connect('button_press_event',click)
#
    # plt.ioff()
    return fig
802568
def plot_sens_center(self, frequency=2):
        
        try:
            colors = np.loadtxt(self.volt_file, skiprows=1)
        except IOError:
            print('IOError opening {0}'.format(volt_file))
            exit()

        # check for 1-dimensionality
        if(len(colors.shape) > 1):
            print('Artificial or Multi frequency data')
            colors = colors[:, frequency].flatten()

        colors = colors[~np.isnan(colors)]

        elem.load_elem_file(self.elem_file)
        elem.load_elec_file(self.elec_file)
        nr_elements = len(elem.element_type_list[0])
        elem.element_data = np.zeros((nr_elements, 1)) * np.nan

        elem.plt_opt.title = ' '
        elem.plt_opt.reverse = True
        elem.plt_opt.cbmin = -1
        elem.plt_opt.cbmax = 1
        elem.plt_opt.cblabel = self.cblabel
        elem.plt_opt.xlabel = 'x (m)'
        elem.plt_opt.ylabel = 'z (m)'

        fig = plt.figure(figsize=(5, 7))
        ax = fig.add_subplot(111)
        ax, pm, cb = elem.plot_element_data_to_ax(0, ax, scale='linear',
                                                  no_cb=True)
        ax.scatter(self.sens_centers[:, 0], self.sens_centers[:, 1], c=colors,
                   s=100, edgecolors='none')

        cb_pos = mpl_get_cb_bound_next_to_plot(ax)
        ax1 = fig.add_axes(cb_pos, frame_on=True)
        cmap = mpl.cm.jet_r
        norm = mpl.colors.Normalize(vmin=np.nanmin(colors),
                                    vmax=np.nanmax(colors))
        mpl.colorbar.ColorbarBase(ax1, cmap=cmap, norm=norm,
                                  orientation='vertical')

        fig.savefig(self.output_file, bbox_inches='tight', dpi=300)
1131019
def plot_gaussian_2D(mu, lmbda, color='b', centermarker=True,label='',alpha=1.,ax=None,artists=None):
    '''
    
    '''
    assert len(mu) == 2
    ax = ax if ax else plt.gca()

    # TODO use artists!

    t = np.hstack([np.arange(0,2*np.pi,0.01),0])
    circle = np.vstack([np.sin(t),np.cos(t)])
    ellipse = np.dot(np.linalg.cholesky(lmbda),circle)

    if artists is None:
        point = ax.scatter([mu[0]],[mu[1]],marker='D',color=color,s=4,alpha=alpha) \
                if centermarker else None
        line, = ax.plot(ellipse[0,:] + mu[0], ellipse[1,:] + mu[1],linestyle='-',
                linewidth=2,color=color,label=label,alpha=alpha)
    else:
        line, point = artists
        if centermarker:
            point.set_offsets(np.atleast_2d(mu))
        line.set_xdata(ellipse[0,:] + mu[0])
        line.set_ydata(ellipse[1,:] + mu[1])
        line.set_alpha(alpha)
        line.set_color(color)

    return line, point
368016
def plot(self, vertices, show=False):
        
        if vertices.shape[1] != 2:
            raise ValueError('only for 2D points!')

        import matplotlib.pyplot as plt

        # get rotation angle in degrees
        angle = np.degrees(self.angle(vertices))

        plt.text(*vertices[self.origin],
                 s=self.text,
                 rotation=angle,
                 ha=self.align[0],
                 va=self.align[1],
                 size=18)

        if show:
            plt.show()
1002715
def plotit(self, x, y, fields, colors=[]):
        ''''''
        pylab.ion()
        fig = pylab.figure(num=1, figsize=(12,6))
        ax1 = fig.gca()
        ax2 = None
        xrange = 0.0
        for i in range(0, len(fields)):
            if len(x[i]) == 0: continue
            if self.lowest_x is None or x[i][0] < self.lowest_x:
                self.lowest_x = x[i][0]
            if self.highest_x is None or x[i][-1] > self.highest_x:
                self.highest_x = x[i][-1]
        if self.highest_x is None or self.lowest_x is None:
            return
        xrange = self.highest_x - self.lowest_x
        xrange *= 24 * 60 * 60
        self.formatter = matplotlib.dates.DateFormatter('%H:%M:%S')
        interval = 1
        intervals = [ 1, 2, 5, 10, 15, 30, 60, 120, 240, 300, 600,
                      900, 1800, 3600, 7200, 5*3600, 10*3600, 24*3600 ]
        for interval in intervals:
            if xrange / interval < 15:
                break
        locator = matplotlib.dates.SecondLocator(interval=interval)
        if not self.xaxis:
            ax1.xaxis.set_major_locator(locator)
            ax1.xaxis.set_major_formatter(self.formatter)
        empty = True
        ax1_labels = []
        ax2_labels = []

        for i in range(0, len(fields)):
            if len(x[i]) == 0:
                print("Failed to find any values for field %s" % fields[i])
                continue
            if i < len(colors):
                color = colors[i]
            else:
                color = 'red'
                (tz, tzdst) = time.tzname

            if self.axes[i] == 2:
                if ax2 == None:
                    ax2 = ax1.twinx()
                    ax2.format_coord = self.make_format(ax2, ax1)
                ax = ax2
                if not self.xaxis:
                    ax2.xaxis.set_major_locator(locator)
                    ax2.xaxis.set_major_formatter(self.formatter)
                label = fields[i]
                if label.endswith(":2"):
                    label = label[:-2]
                ax2_labels.append(label)
            else:
                ax1_labels.append(fields[i])
                ax = ax1
            
            if self.xaxis:
                if self.marker is not None:
                    marker = self.marker
                else:
                    marker = '+'
                if self.linestyle is not None:
                    linestyle = self.linestyle
                else:
                    linestyle = 'None'
                ax.plot(x[i], y[i], color=color, label=fields[i],
                        linestyle=linestyle, marker=marker)
            else:
                if self.marker is not None:
                    marker = self.marker
                else:
                    marker = 'None'
                if self.linestyle is not None:
                    linestyle = self.linestyle
                else:
                    linestyle = '-'
                ax.plot_date(x[i], y[i], color=color, label=fields[i],
                             linestyle=linestyle, marker=marker, tz=None)

            empty = False
            if self.flightmode is not None:
                for i in range(len(self.modes)-1):
                    c = colourmap[self.flightmode].get(self.modes[i][1], edge_colour)
                    ax1.axvspan(self.modes[i][0], self.modes[i+1][0], fc=c, ec=edge_colour, alpha=0.1)
                c = colourmap[self.flightmode].get(self.modes[-1][1], edge_colour)
                ax1.axvspan(self.modes[-1][0], ax1.get_xlim()[1], fc=c, ec=edge_colour, alpha=0.1)

            if ax1_labels != []:
                ax1.legend(ax1_labels,loc=self.legend)
            if ax2_labels != []:
                ax2.legend(ax2_labels,loc=self.legend2)
            if empty:
                print("No data to graph")
                return
1014533
def hist2d(x, y, label=None, opacity=None):
    
    x = np.atleast_1d(x)
    y = np.atleast_1d(y)
    data = [go.Histogram2d(x=x, y=y, opacity=opacity, name=label)]
    return Chart(data=data)
776318
public static PlotCanvas plot(double[][] z) {
        double[] lowerBound = {0, 0};
        double[] upperBound = {z[0].length, z.length};
        PlotCanvas canvas = new PlotCanvas(lowerBound, upperBound, false);
        canvas.add(new Heatmap(z));

        canvas.getAxis(0).setFrameVisible(false);
        canvas.getAxis(0).setLabelVisible(false);
        canvas.getAxis(0).setGridVisible(false);
        canvas.getAxis(1).setFrameVisible(false);
        canvas.getAxis(1).setLabelVisible(false);
        canvas.getAxis(1).setGridVisible(false);

        return canvas;
    }
467196
def local_bifurcation_angles(neurites, neurite_type=NeuriteType.all):
    ''''''
    return map_sections(_bifurcationfunc.local_bifurcation_angle,
                        neurites,
                        neurite_type=neurite_type,
                        iterator_type=Tree.ibifurcation_point)
158018
def plotBasis(self, filename=None):
    
    if np.floor(np.sqrt(self.filterDim)) ** 2 != self.filterDim:
      print "Basis visualization is not available if filterDim is not a square."
      return

    dim = int(np.sqrt(self.filterDim))

    if np.floor(np.sqrt(self.outputDim)) ** 2 != self.outputDim:
      outDimJ = np.sqrt(np.floor(self.outputDim / 2))
      outDimI = np.floor(self.outputDim / outDimJ)
      if outDimI > outDimJ:
        outDimI, outDimJ = outDimJ, outDimI
    else:
      outDimI = np.floor(np.sqrt(self.outputDim))
      outDimJ = outDimI

    outDimI, outDimJ = int(outDimI), int(outDimJ)
    basis = - np.ones((1 + outDimI * (dim + 1), 1 + outDimJ * (dim + 1)))

    # populate array with basis values
    k = 0
    for i in xrange(outDimI):
      for j in xrange(outDimJ):
        colorLimit = np.max(np.abs(self.basis[:, k]))
        mat = np.reshape(self.basis[:, k], (dim, dim)) / colorLimit
        basis[1 + i * (dim + 1) : 1 + i * (dim + 1) + dim, \
              1 + j * (dim + 1) : 1 + j * (dim + 1) + dim] = mat
        k += 1

    plt.figure()
    plt.subplot(aspect="equal")
    plt.pcolormesh(basis)

    plt.axis([0, 1 + outDimJ * (dim + 1), 0, 1 + outDimI * (dim + 1)])
    # remove ticks
    plt.gca().xaxis.set_major_locator(plt.NullLocator())
    plt.gca().yaxis.set_major_locator(plt.NullLocator())
    plt.title("Basis functions for {0}".format(self))

    if filename is not None:
      plt.savefig(filename)
750494
public static PlotCanvas plot(double[] x, double[] y, double[][] z) {
        double[] lowerBound = {Math.min(x), Math.min(y), Math.min(z)};
        double[] upperBound = {Math.max(x), Math.max(y), Math.max(z)};

        PlotCanvas canvas = new PlotCanvas(lowerBound, upperBound);

        Surface surface = new Surface(x, y, z);
        canvas.add(surface);

        return canvas;
    }
884348
def n_segments(neurites, neurite_type=NeuriteType.all):
    ''''''
    return sum(len(s.points) - 1
               for s in iter_sections(neurites, neurite_filter=is_type(neurite_type)))
1188427
def extract_density(population, plane='xy', bins=100, neurite_type=NeuriteType.basal_dendrite):
    '''
    '''
    segment_midpoints = get_feat('segment_midpoints', population, neurite_type=neurite_type)
    horiz = segment_midpoints[:, 'xyz'.index(plane[0])]
    vert = segment_midpoints[:, 'xyz'.index(plane[1])]
    return np.histogram2d(np.array(horiz), np.array(vert), bins=(bins, bins))