示例#1
0
    def _plot(self, trial, figure, invert_colors=False, line_width=1, 
            max_drawn=250, opacity=0.25, point_size=2):
        features = trial.features.data

        def as_frac(x=None, y=None):
            f = figure
            canvas_size_in_pixels = (f.get_figwidth()*f.get_dpi(),
                                    f.get_figheight()*f.get_dpi())
            return as_fraction(x=x, y=y, 
                    canvas_size_in_pixels=canvas_size_in_pixels)

        figure.set_facecolor(background[invert_colors])
        figure.set_edgecolor(foreground[invert_colors])
        figure.subplots_adjust(left=as_frac(x=80), 
                right=1.0-as_frac(x=35), 
                bottom=as_frac(y=40), 
                top=1.0-as_frac(y=25))

        axes = figure.add_subplot(111)

        
        for feature in sample_data(features, max_drawn):
            if point_size > 0:
                marker = 'o'
            else:
                marker = ''
            axes.plot(feature, color=line_color[invert_colors],
                alpha=opacity, 
                linewidth=line_width, 
                marker=marker,
                markeredgecolor=line_color[invert_colors],
                markerfacecolor=foreground[invert_colors],
                markersize=point_size)

        axes.text(0.98, 0.95, '%d drawn' % min(max_drawn, len(features)), 
                color=foreground[invert_colors],
                horizontalalignment='right', 
                verticalalignment='center', 
                transform=axes.transAxes)

        axes.set_ylabel('Feature Amplitude', color=foreground[invert_colors])
        axes.set_xlabel('Feature Index (found features for %d events)' % len(features), 
                color=foreground[invert_colors])

        # axes color fixing
        frame = axes.patch
        frame.set_facecolor(background[invert_colors])
        frame.set_edgecolor(foreground[invert_colors])
        for spine in axes.spines.values():
            spine.set_color(foreground[invert_colors])
        lines = axes.get_xticklines()
        lines.extend(axes.get_yticklines())
        for line in lines:
            line.set_color(foreground[invert_colors])
        labels = axes.get_xticklabels()
        labels.extend(axes.get_yticklabels())
        for label in labels:
            label.set_color(foreground[invert_colors])
示例#2
0
    def _plot(self, trial, figure, invert_colors=False, line_width=1, 
            max_drawn=250, opacity=0.25, point_size=2, legend=False):
        features = trial.features.data

        def as_frac(x=None, y=None):
            f = figure
            canvas_size_in_pixels = (f.get_figwidth()*f.get_dpi(),
                                    f.get_figheight()*f.get_dpi())
            return as_fraction(x=x, y=y, 
                    canvas_size_in_pixels=canvas_size_in_pixels)

        figure.set_facecolor(background[invert_colors])
        figure.set_edgecolor(foreground[invert_colors])
        figure.subplots_adjust(left=as_frac(x=80), 
                right=1.0-as_frac(x=35), 
                bottom=as_frac(y=40), 
                top=1.0-as_frac(y=25))

        axes = figure.add_subplot(111)

        cfs = trial.clustered_features
        for i, cluster_name in enumerate(sorted(cfs.keys())):
            features = cfs[cluster_name]
            num_drawn = min(max_drawn, len(features))
            color=cluster_colors[invert_colors][
                    i%len(cluster_colors[invert_colors])]
            if point_size > 0:
                marker = 'o'
            else:
                marker = ''
            label = None
            alpha = opacity
            for feature in sample_data(features, max_drawn):
                axes.plot(feature, 
                    color=color,
                    alpha=alpha, 
                    linewidth=line_width, 
                    marker=marker,
                    markeredgecolor=foreground[invert_colors],
                    markerfacecolor=color,
                    markersize=point_size,
                    label=label)

            # plot the average spike window for this cluster.
            average_feature = numpy.average(features, axis=0)
            label = '%s: %d of %d drawn' % (cluster_name, 
                    num_drawn, len(features))
            alpha = 1.0

            axes.plot(average_feature, 
                color=color,
                alpha=alpha, 
                linewidth=line_width, 
                marker=marker,
                markeredgecolor=foreground[invert_colors],
                markerfacecolor=color,
                markersize=point_size,
                label=label)

        axes.set_ylabel('Feature Amplitude', color=foreground[invert_colors])
        axes.set_xlabel('Feature Index', 
                color=foreground[invert_colors])

        # axes color fixing
        frame = axes.patch
        frame.set_facecolor(background[invert_colors])
        frame.set_edgecolor(foreground[invert_colors])
        for spine in axes.spines.values():
            spine.set_color(foreground[invert_colors])
        lines = axes.get_xticklines()
        lines.extend(axes.get_yticklines())
        for line in lines:
            line.set_color(foreground[invert_colors])
        labels = axes.get_xticklabels()
        labels.extend(axes.get_yticklabels())
        for label in labels:
            label.set_color(foreground[invert_colors])

        # setup legend
        if legend:
            l = axes.legend(loc='upper right')
            frame = l.get_frame()
            frame.set_facecolor(background[invert_colors])
            frame.set_edgecolor(foreground[invert_colors])
            for text in l.texts:
                text.set_color(foreground[invert_colors])
    def _plot(self, trial, figure, invert_colors=False, line_width=1, 
            max_drawn=250, opacity=0.25, point_size=0, 
            spikes='Detection Filtered', legend=False):

        def as_frac(x=None, y=None):
            f = figure
            canvas_size_in_pixels = (f.get_figwidth()*f.get_dpi(),
                                    f.get_figheight()*f.get_dpi())
            return as_fraction(x=x, y=y, 
                    canvas_size_in_pixels=canvas_size_in_pixels)

        figure.set_facecolor(background[invert_colors])
        figure.set_edgecolor(foreground[invert_colors])
        figure.subplots_adjust(left=as_frac(x=80), 
                right=1.0-as_frac(x=35), 
                bottom=as_frac(y=40), 
                top=1.0-as_frac(y=25))

        axes = figure.add_subplot(111)

        if spikes == 'Detection Filtered':
            csws = trial.clustered_df_spike_windows
            sampling_freq = trial.df_sampling_freq.data
        else:
            csws = trial.clustered_ef_spike_windows
            sampling_freq = trial.ef_sampling_freq.data
        times = numpy.arange(0, csws.values()[0].shape[-1],
                dtype=numpy.float64)/sampling_freq*1000.0

        # plot the spike windows
        for i, cluster_name in enumerate(sorted(csws.keys())):
            spike_windows = csws[cluster_name]
            num_drawn = min(max_drawn, len(spike_windows))
            color=cluster_colors[invert_colors][
                    i%len(cluster_colors[invert_colors])]
            if point_size > 0:
                marker = 'o'
            else:
                marker = ''
            label = None
            alpha = opacity
            for spike_window in sample_data(spike_windows, max_drawn):
                axes.plot(times, spike_window, 
                    color=color,
                    alpha=alpha, 
                    linewidth=line_width, 
                    marker=marker,
                    markeredgecolor=foreground[invert_colors],
                    markerfacecolor=color,
                    markersize=point_size,
                    label=label)

            # plot the average spike window for this cluster.
            average_spike_window = numpy.average(spike_windows, axis=0)
            label = '%s: %d of %d drawn' % (cluster_name, 
                    num_drawn, len(spike_windows))
            alpha = 1.0

            axes.plot(times, average_spike_window, 
                color=color,
                alpha=alpha, 
                linewidth=line_width, 
                marker=marker,
                markeredgecolor=foreground[invert_colors],
                markerfacecolor=color,
                markersize=point_size,
                label=label)

        axes.set_ylabel('Amplitude (mV)', color=foreground[invert_colors])
        axes.set_xlabel('Time (ms)', 
                color=foreground[invert_colors])

        # axes color fixing
        frame = axes.patch
        frame.set_facecolor(background[invert_colors])
        frame.set_edgecolor(foreground[invert_colors])
        for spine in axes.spines.values():
            spine.set_color(foreground[invert_colors])
        lines = axes.get_xticklines()
        lines.extend(axes.get_yticklines())
        for line in lines:
            line.set_color(foreground[invert_colors])
        labels = axes.get_xticklabels()
        labels.extend(axes.get_yticklabels())
        for label in labels:
            label.set_color(foreground[invert_colors])

        # setup legend
        if legend:
            l = axes.legend(loc='upper right')
            frame = l.get_frame()
            frame.set_facecolor(background[invert_colors])
            frame.set_edgecolor(foreground[invert_colors])
            for text in l.texts:
                text.set_color(foreground[invert_colors])