def autocorrs(self, clusters=None, bin_width=0.0015, limit=0.03, figsize=None): """ Plots of autocorrelations of clustered spike times. **Keywords**: *clusters*: list or iterable List of clusters to plot *bin_width*: float Width of bins in the autocorrelation calculation *limit*: float Time limit over which to calculate the autocorrelation """ cls = self.clusters.select(clusters) cl_times = cls.times() colors = plt.get_colors(max(self.clusters.keys()) + 1, self.cm) fig, axes = plt.generate_axes(len(cls), 4, num=3, figsize=figsize, sharex=True) for ax, cl in zip(axes, cl_times): ax.clear() tstamps = cl_times[cl] plt.autocorr(tstamps, ax=ax, color=colors[cl], bin_width=bin_width, limit=limit) ax.set_title('Cluster {}'.format(cl)) ax.set_xlabel('Lag (ms)') fig.tight_layout() return fig
def spikes(self, clusters=None, limit=50, figsize=None): """ Generates plots of clustered spike waveforms. """ cls = self.clusters.select(clusters) cl_spikes = cls.spikes() colors = plt.get_colors(max(self.clusters.keys()) + 1, self.cm) fig, axes = plt.generate_axes(len(cls), 4, num=2, sharex=True, figsize=figsize) for ax, cl in zip(axes, cl_spikes): ax.clear() spks = cl_spikes[cl] plt.spikes(spks, ax=ax, color=colors[cl], patch_size=spks.shape[1] / 4) ax.set_title('Cluster {}'.format(cl)) ax.set_ylabel('Voltage (uV)') ax.set_xticklabels('') fig.tight_layout() return fig
def scatter(self, clusters=None, components=[1, 2, 3], limit=500, figsize=(16, 5), s=5): """ Generates a scatter plot in feature space of the clustered data. """ from scipy.misc import comb from itertools import combinations components = [c - 1 for c in components] feats, col_array = self._scatter_helper(clusters, limit) N_plots = int(comb(len(components), 2, exact=True)) fig, axes = plt.generate_axes(N_plots, ncols=3, num=1, figsize=figsize) for ax, (x, y) in zip(axes, combinations(components, 2)): ax.clear() # Clear the axes before replotting plt.scatter(feats[:, x], feats[:, y], colors=col_array, ax=ax, s=s) ax.set_xlabel("Component {}".format(x + 1)) ax.set_ylabel("Component {}".format(y + 1)) fig.tight_layout() return fig
def feature_trace(self, dimension, clusters=None, marker='o', color='k', xlims=(0,4000), figsize=(9,6)): clusters = self.clusters.select(clusters) fig, axes = plt.generate_axes(len(clusters), 2, figsize=figsize) for cl, ax in zip(clusters, axes): plt.feature_trace(clusters[cl]['feats'][:, dimension], clusters[cl]['times'], ax=ax, color=color, marker=marker, xlims=xlims) ax.set_title('Cluster {}'.format(cl)) fig.tight_layout() return fig
def timestamps(self, clusters=None, color='k', xlims=(0,4000), figsize=(9,6)): """ Plot the timestamps for clusters. """ clusters = self.clusters.select(clusters) times = clusters.times() fig, axes = plt.generate_axes(len(clusters), 2, figsize=figsize) for cl, ax in zip(times, axes): plt.timestamps(times[cl], ax=ax, color=color, xlims=xlims) ax.set_title('Cluster {}'.format(cl)) fig.tight_layout() return fig
def timestamps(self, clusters=None, color='k', xlims=(0, 4000), figsize=(9, 6)): """ Plot the timestamps for clusters. """ clusters = self.clusters.select(clusters) times = clusters.times() fig, axes = plt.generate_axes(len(clusters), 2, figsize=figsize) for cl, ax in zip(times, axes): plt.timestamps(times[cl], ax=ax, color=color, xlims=xlims) ax.set_title('Cluster {}'.format(cl)) fig.tight_layout() return fig
def scatter(self, clusters=None, components=[1,2,3], limit=500, figsize=(16,5), s=5): """ Generates a scatter plot in feature space of the clustered data. """ from scipy.misc import comb from itertools import combinations components = [ c-1 for c in components ] feats, col_array = self._scatter_helper(clusters, limit) N_plots = int(comb(len(components), 2, exact=True)) fig, axes = plt.generate_axes(N_plots, ncols=3, num=1, figsize=figsize) for ax, (x,y) in zip(axes,combinations(components,2)): ax.clear() # Clear the axes before replotting plt.scatter(feats[:,x], feats[:,y], colors=col_array, ax=ax, s=s) ax.set_xlabel("Component {}".format(x+1)) ax.set_ylabel("Component {}".format(y+1)) fig.tight_layout() return fig
def feature_trace(self, dimension, clusters=None, marker='o', color='k', xlims=(0, 4000), figsize=(9, 6)): clusters = self.clusters.select(clusters) fig, axes = plt.generate_axes(len(clusters), 2, figsize=figsize) for cl, ax in zip(clusters, axes): plt.feature_trace(clusters[cl]['feats'][:, dimension], clusters[cl]['times'], ax=ax, color=color, marker=marker, xlims=xlims) ax.set_title('Cluster {}'.format(cl)) fig.tight_layout() return fig
def spikes(self, clusters=None, limit=50, figsize=None): """ Generates plots of clustered spike waveforms. """ cls = self.clusters.select(clusters) cl_spikes = cls.spikes() colors = plt.get_colors(max(self.clusters.keys()) + 1, self.cm) fig, axes = plt.generate_axes(len(cls), 4, num=2, sharex=True, figsize=figsize) for ax, cl in zip(axes, cl_spikes): ax.clear() spks = cl_spikes[cl] plt.spikes(spks, ax=ax, color=colors[cl], patch_size=spks.shape[1]/4) ax.set_title('Cluster {}'.format(cl)) ax.set_ylabel('Voltage (uV)') ax.set_xticklabels('') fig.tight_layout() return fig