Example #1
0
def _timeseries_mean_and_error(y, std, *args, axis=-1, center=True, **kwargs):
    # TODO/FIXME: You must multiply by ones(plates) in order to plot
    # broadcasted plates properly

    shape = list(np.shape(y))

    # Get and remove the length of the time axis
    T = shape.pop(axis)

    # Move time axis to first
    y = np.rollaxis(y, axis)
    if std is not None:
        std = np.rollaxis(std, axis)

    y = np.reshape(y, (T, -1))
    if std is not None:
        std = np.reshape(std, (T, -1))

    # Remove 1s
    shape = [s for s in shape if s > 1]

    # Calculate number of rows and columns
    shape = utils.multiply_shapes(shape, (1, 1))
    if len(shape) > 2:
        raise Exception("Can plot only in 2 dimensions (rows and columns)")
    (M, N) = shape

    # Prefer plotting to rows
    if M == 1:
        M = N
        N = 1

    # Plot each timeseries
    ax0 = plt.subplot(M, N, 1)
    for i in range(M * N):
        if i > 0:
            # Share x axis between all subplots
            ax = plt.subplot(M, N, i + 1, sharex=ax0)
        else:
            ax = ax0

        # Autoscale the axes to data and use tight y and x axes
        ax.autoscale(enable=True, tight=True)
        ax.set_ylim(auto=True)

        if i < (M - 1) * N:
            # Remove x tick labels from other than the last row
            plt.setp(ax.get_xticklabels(), visible=False)

        if std is None:
            plt.plot(y[:, i], *args, **kwargs)
        else:
            if len(args) > 0:
                raise Exception("Can't handle extra arguments")
            errorplot(y=y[:, i], error=std[:, i], **kwargs)

        if center:
            # Center the zero level on y-axis
            ylim = ax.get_ylim()
            vmax = np.max(np.abs(ylim))
            ax.set_ylim([-vmax, vmax])

    # Remove height space between subplots
    plt.subplots_adjust(hspace=0)
Example #2
0
 def _plates_from_parent(self, index):
     return tuple(utils.multiply_shapes(self.parents[index].plates,
                                        tiles))
Example #3
0
 def _plates_from_parent(self, index):
     return tuple(utils.multiply_shapes(self.parents[index].plates,
                                        tiles))
Example #4
0
def _timeseries_mean_and_error(y, std, *args, axis=-1, center=True, **kwargs):
    # TODO/FIXME: You must multiply by ones(plates) in order to plot
    # broadcasted plates properly
    
    shape = list(np.shape(y))

    # Get and remove the length of the time axis
    T = shape.pop(axis)

    # Move time axis to first
    y = np.rollaxis(y, axis)
    if std is not None:
        std = np.rollaxis(std, axis)
    
    y = np.reshape(y, (T, -1))
    if std is not None:
        std = np.reshape(std, (T, -1))

    # Remove 1s
    shape = [s for s in shape if s > 1]

    # Calculate number of rows and columns
    shape = utils.multiply_shapes(shape, (1,1))
    if len(shape) > 2:
        raise Exception("Can plot only in 2 dimensions (rows and columns)")
    (M, N) = shape

    # Prefer plotting to rows
    if M == 1:
        M = N
        N = 1

    # Plot each timeseries
    ax0 = plt.subplot(M, N, 1)
    for i in range(M*N):
        if i > 0:
            # Share x axis between all subplots
            ax = plt.subplot(M, N, i+1, sharex=ax0)
        else:
            ax = ax0

        # Autoscale the axes to data and use tight y and x axes
        ax.autoscale(enable=True, tight=True)
        ax.set_ylim(auto=True)

        if i < (M-1)*N - 1:
            # Remove x tick labels from other than the last row
            ax.set_xticklabels([])

        if std is None:
            plt.plot(y[:,i], *args, **kwargs)
        else:
            if len(args) > 0:
                raise Exception("Can't handle extra arguments")
            errorplot(y=y[:,i], error=std[:,i], **kwargs)

        if center:
            # Center the zero level on y-axis
            ylim = ax.get_ylim()
            vmax = np.max(np.abs(ylim))
            ax.set_ylim([-vmax, vmax])

    # Remove height space between subplots
    plt.subplots_adjust(hspace=0)