def shapeplot(h,ax,sections=None,order='pre',cvals=None,\
              clim=None,cmap=cm.YlOrBr_r, legend=True,  **kwargs):  # meanLineWidth=1.0, maxLineWidth=10.0,
    """
    Plots a 3D shapeplot

    Args:
        h = hocObject to interface with neuron
        ax = matplotlib axis for plotting
        sections = list of h.Section() objects to be plotted
        order = { None= use h.allsec() to get sections
                  'pre'= pre-order traversal of morphology }
        cvals = list/array with values mapped to color by cmap; useful
                for displaying voltage, calcium or some other state
                variable across the shapeplot.
        **kwargs passes on to matplotlib (e.g. color='r' for red lines)

    Returns:
        lines = list of line objects making up shapeplot
    """
    
    # Default is to plot all sections. 
    if sections is None:
        if order == 'pre':
            sections = allsec_preorder(h) # Get sections in "pre-order"
        else:
            sections = list(h.allsec())
    
    # Determine color limits
    if cvals is not None and clim is None: 
        clim = [np.nanmin(cvals), np.nanmax(cvals)]

    # Plot each segement as a line
    lines = []
    i = 0

    allDiams = []
    for sec in sections:
        allDiams.append(get_section_diams(h,sec))
    #maxDiams = max([max(d) for d in allDiams])
    #meanDiams = np.mean([np.mean(d) for d in allDiams])

    for isec,sec in enumerate(sections):
        xyz = get_section_path(h,sec)
        seg_paths = interpolate_jagged(xyz,sec.nseg)
        diams = allDiams[isec]  # represent diams as linewidths
        linewidths = diams # linewidth is in points so can use actual diams to plot
        # linewidths = [min(d/meanDiams*meanLineWidth, maxLineWidth) for d in diams]  # use if want to scale size 

        for (j,path) in enumerate(seg_paths):
            line, = plt.plot(path[:,0], path[:,1], path[:,2], '-k', **kwargs)
            try:
                line.set_linewidth(linewidths[j])
            except:
                pass
            if cvals is not None:
                if isinstance(cvals[i], numbers.Number):
                    # map number to colormap
                    try:
                        col = cmap(int((cvals[i]-clim[0])*255/(clim[1]-clim[0])))
                    except:
                        col = cmap(0)
                else:
                    # use input directly. E.g. if user specified color with a string.
                    col = cvals[i]
                line.set_color(col)
            lines.append(line)
            i += 1
    return lines
Plots a 3D shapeplot

    Args:
        h = hocObject to interface with neuron
        ax = matplotlib axis for plotting
        sections = list of h.Section() objects to be plotted
        order = { None= use h.allsec() to get sections
                  'pre'= pre-order traversal of morphology }
        cvals = list/array with values mapped to color by cmap; useful
                for displaying voltage, calcium or some other state
                variable across the shapeplot.
        **kwargs passes on to matplotlib (e.g. color='r' for red lines)

    Returns:
        lines = list of line objects making up shapeplot