Exemplo n.º 1
0
def signalPlot(t, sig, ax, timeUnits="ms", nticks=3, nThetaTicks=None, **kw):
    '''
    Plot a customized signal plot into an axis.

    Parameters
    ----------
    t : numpy array
        Time array
    sig : numpy array
        Signal values
    ax : matplotlib.axes object
        Axes to plot into
    xlabel : string
        X label
    ylabel : string
        Y label
    timeUnits : string
        Time units to be appended to xlabe
    leg : list of strings or None
        Legend to print. If None, do not print any legend
    nticks : int
        Number of ticks on the yaxis
    '''
    xlabel    = kw.pop('xlabel', 'Time (%s)' % timeUnits)
    ylabel    = kw.pop('ylabel', '')
    ylabelPos = kw.pop('ylabelPos', -0.22)
    xmargin   = kw.pop('xmargin', 0)
    zeroLine  = kw.pop('zeroLine', True)

    plt.hold('on')
    globalAxesSettings(ax)
    if nThetaTicks is not None:
        xticks = np.linspace(t[0], t[-1], nThetaTicks)
        ax.set_xticks(xticks)
        plt.grid(b=True, which='major', axis='x')
    else:
        ax.xaxis.set_major_locator(ti.MaxNLocator(4))
    ax.yaxis.set_major_locator(ti.MaxNLocator(nticks-1))
    ax.xaxis.set_minor_locator(ti.AutoMinorLocator(2))
    ax.plot(t, sig, **kw)
    ax.set_xlabel(xlabel)
    ax.text(ylabelPos, 0.5, ylabel, va='center', ha='center',
            transform=ax.transAxes, rotation=90)

    ax.spines['top'].set_visible(False)
    ax.spines['right'].set_visible(False)
    w = t[-1] - t[0]
    ax.set_xlim([t[0] - xmargin*w, t[-1] + xmargin*w])

    if (zeroLine):
        color  = rcp['grid.color']
        ls     = rcp['grid.linestyle']
        lw     = rcp['grid.linewidth']
        alphsa = rcp['grid.alpha']
        ax.axhline(0, ls=ls, lw=lw, color=color)
Exemplo n.º 2
0
def plotConnHistogram(val, **kw):
    '''
    Plot a histogram of connection weights with some predetermined formatting.

    Parameters
    ----------
    val : numpy array
        A 1D array of connetions.
    **kw
        Keyword arguments to the hist function. See code for some additional
        keyword arguments.
    '''
    # keyword arguments
    kw['bins'] = kw.get('bins', 20)
    #kw['edgecolor'] = kw.get('edgecolor', 'none')
    ax = kw.pop('ax', plt.gca())
    xlabel = kw.pop('xlabel', 'g (nS)')
    ylabel = kw.pop('ylabel', 'Count')
    title = kw.pop('title', '')
    locators = kw.pop('locators', {})
    ylabelPos = kw.pop('ylabelPos', -0.2)

    globalAxesSettings(ax)
    n, _, _ = ax.hist(val, **kw)
    print(np.max(n))
    ax.set_xlabel(xlabel)
    ax.text(ylabelPos,
            0.5,
            ylabel,
            rotation=90,
            transform=ax.transAxes,
            va='center',
            ha='right')
    ax.set_title(title)

    # tick formatting
    x_major = locators.get('x_major', ti.MaxNLocator(3))
    x_minor = locators.get('x_minor', ti.AutoMinorLocator(2))
    y_major = locators.get('y_major', ti.LinearLocator(2))
    y_minor = locators.get('y_minor', ti.AutoMinorLocator(4))
    ax.xaxis.set_major_locator(x_major)
    ax.yaxis.set_major_locator(y_major)
    ax.xaxis.set_minor_locator(x_minor)
    ax.yaxis.set_minor_locator(y_minor)

    ax.spines['top'].set_visible(False)
    ax.spines['right'].set_visible(False)

    return ax
Exemplo n.º 3
0
def plotConnHistogram(val, **kw):
    '''
    Plot a histogram of connection weights with some predetermined formatting.

    Parameters
    ----------
    val : numpy array
        A 1D array of connetions.
    **kw
        Keyword arguments to the hist function. See code for some additional
        keyword arguments.
    '''
    # keyword arguments
    kw['bins']      = kw.get('bins', 20)
    #kw['edgecolor'] = kw.get('edgecolor', 'none')
    ax              = kw.pop('ax', plt.gca())
    xlabel          = kw.pop('xlabel', 'g (nS)')
    ylabel          = kw.pop('ylabel', 'Count')
    title           = kw.pop('title', '')
    locators        = kw.pop('locators', {})
    ylabelPos       = kw.pop('ylabelPos', -0.2)

    globalAxesSettings(ax)
    n, _, _ = ax.hist(val, **kw)
    print(np.max(n))
    ax.set_xlabel(xlabel)
    ax.text(ylabelPos, 0.5, ylabel, rotation=90, transform=ax.transAxes,
            va='center', ha='right')
    ax.set_title(title)

    # tick formatting
    x_major = locators.get('x_major', ti.MaxNLocator(3))
    x_minor = locators.get('x_minor', ti.AutoMinorLocator(2))
    y_major = locators.get('y_major', ti.LinearLocator(2))
    y_minor = locators.get('y_minor', ti.AutoMinorLocator(4))
    ax.xaxis.set_major_locator(x_major)
    ax.yaxis.set_major_locator(y_major)
    ax.xaxis.set_minor_locator(x_minor)
    ax.yaxis.set_minor_locator(y_minor)

    ax.spines['top'].set_visible(False)
    ax.spines['right'].set_visible(False)

    return ax
Exemplo n.º 4
0
def EIPlot(E, I, labelx=None, labely="", holdVal='on', timeUnits="ms",
        leg=['middle', 'edge'], nticks=3):
    '''
    Plot a double plot of E and I variable.

    Parameters
    ----------
    E : A pair (sig, times)
        Excitatory variable.
    I : A pair (sig, times)
        Inhibitory variable.
    holdVal : str
        Value to pass on to the hold() function
    '''

    plt.hold('on')
    ax = plt.subplot(211)
    globalAxesSettings(plt.gca())
    plt.gca().xaxis.set_major_locator(ti.MaxNLocator(4))
    plt.gca().yaxis.set_major_locator(ti.MaxNLocator(nticks-1))
    plt.plot(E[1], E[0])
    if (labely != ""):
        plt.ylabel("E cell " + labely)
    plt.legend(leg)

    plt.subplot(212, sharex=ax)
    globalAxesSettings(plt.gca())
    plt.gca().xaxis.set_major_locator(ti.MaxNLocator(4))
    plt.gca().yaxis.set_major_locator(ti.MaxNLocator(nticks-1))
    plt.plot(I[1], I[0])
    if (labely != ""):
        plt.ylabel("I cell " + labely)
    if (labelx is None):
        plt.xlabel('Time (%s)' % timeUnits)
    elif (labelx != ""):
        plt.xlabel(labelx)
    plt.legend(leg)

    plt.tight_layout(w_pad=1.0)
Exemplo n.º 5
0
def plot2DWeightMatrix(C, **kw):
    ax = kw.pop('ax', plt.gca())
    xlabel = kw.pop('xlabel', 'Neuron #')
    ylabel = kw.pop('ylabel', 'Neuron #')
    labelpad = kw.pop('labelpad', None)
    title = kw.pop('title', '')
    kw['rasterized'] = kw.get('rasterized', True)

    X = np.arange(C.shape[1] + 1)
    Y = np.arange(C.shape[0] + 1)
    globalAxesSettings(ax)
    ax.pcolormesh(X, Y, C, **kw)
    ax.set_xticks([0.5, X[-1] - 0.5])
    ax.set_yticks([0.5, Y[-1] - 0.5])
    ax.set_xticklabels([1, X[-1]])
    ax.set_yticklabels([1, Y[-1]])
    plt.axis('scaled')

    ax.set_xlabel(xlabel, labelpad=labelpad)
    ax.set_ylabel(ylabel, labelpad=labelpad)
    ax.set_title(title, size='small')

    return ax
Exemplo n.º 6
0
def plot2DWeightMatrix(C, **kw):
    ax       = kw.pop('ax', plt.gca())
    xlabel   = kw.pop('xlabel', 'Neuron #')
    ylabel   = kw.pop('ylabel', 'Neuron #')
    labelpad = kw.pop('labelpad', None)
    title    = kw.pop('title', '')
    kw['rasterized'] = kw.get('rasterized', True)

    X = np.arange(C.shape[1] + 1)
    Y = np.arange(C.shape[0] + 1)
    globalAxesSettings(ax)
    ax.pcolormesh(X, Y, C, **kw)
    ax.set_xticks([0.5, X[-1]-0.5])
    ax.set_yticks([0.5, Y[-1]-0.5])
    ax.set_xticklabels([1, X[-1]])
    ax.set_yticklabels([1, Y[-1]])
    plt.axis('scaled')

    ax.set_xlabel(xlabel, labelpad=labelpad)
    ax.set_ylabel(ylabel, labelpad=labelpad)
    ax.set_title(title, size='small')

    return ax
Exemplo n.º 7
0
def parameterScape(fig, X, Y, C, fmts, sizes, cmaps, vranges, **kwargs):
    """
    """
    ax = fig.gca()

    defaultMargin = 1.0
    xmargin = kwargs.pop('xmargin', defaultMargin)
    ymargin = kwargs.pop('ymargin', defaultMargin)
    legend = kwargs.pop('legend', None)
    colorbars = kwargs.pop('colorbars', None)

    sm = []
    colors = []
    for cIdx, c in enumerate(C):
        m = ScalarMappable(cmap=cmaps[cIdx])
        m.set_clim(vranges[cIdx])
        m.set_array(c)
        colors.append(m.to_rgba(c))
        sm.append(m)

    for yIdx, y in enumerate(Y):
        for xIdx, x in enumerate(X):
            for cIdx, c in enumerate(C):
                if (np.isnan(c[yIdx, xIdx])):
                    continue
                ax.plot(x,
                        y,
                        fmts[cIdx],
                        color=colors[cIdx][yIdx, xIdx, :],
                        markersize=sizes[cIdx],
                        **kwargs)

    globalAxesSettings(ax)
    ax.spines['top'].set_visible(False)
    ax.spines['right'].set_visible(False)
    ax.spines['bottom'].set_visible(False)
    ax.spines['left'].set_visible(False)
    ax.tick_params(bottom='off',
                   top='off',
                   left='off',
                   right='off',
                   length=0,
                   pad=-5)
    ax.axis('scaled')
    dx = X[1] - X[0]
    dy = Y[1] - Y[0]
    ax.set_xlim([X[0] - xmargin * dx, X[-1] + xmargin * dx])
    ax.set_ylim([Y[0] - ymargin * dy, Y[-1] + ymargin * dy])

    if (legend is not None):
        legend_strings = legend[0]
        legend_kw = legend[1]
        if (legend_kw is None):
            legend_kw = {}
        parameterScapeLegend(ax, legend_strings, fmts, sizes, cmaps, kwargs,
                             **legend_kw)

    if (colorbars is not None):
        cax = plotColorbars(fig, sm, **colorbars)
    else:
        cax = None

    return ax, cax