def plot_kmeans_components(self, fig1, gs, kmeans_clusters, uncentered_clrs, plot_title='Hb', num_subplots=1, flag_separate=1, gridspecs=[0, 0], model_center=0, removeclusters=0): with sns.axes_style('darkgrid'): if flag_separate: ax1 = fig1.add_subplot(2, 1, num_subplots) else: ax1 = eval('fig1.add_subplot(gs' + gridspecs + ')') if model_center == 1: # Models colors according to trace clrs_cmap = Colorize.optimize(kmeans_clusters.T, asCmap=True) clrs = clrs_cmap.colors else: clrs_cmap = uncentered_clrs clrs = clrs_cmap.colors # Update kmeans if clusters were removed kmeans_clusters_new = copy(kmeans_clusters) if removeclusters != 0: newclrs_updated = copy(clrs_cmap) for index, value in enumerate(clrs_cmap.colors): if index in removeclusters: newclrs_updated.colors[index] = [0, 0, 0] clrs_cmap = newclrs_updated clrs = clrs_cmap.colors for ii in removeclusters: print ii kmeans_clusters_new[:, ii] = zeros(size(kmeans_clusters, 0)) plt.gca().set_color_cycle(clrs) # remove those clusters that are ignored before plotting for ii in xrange(0, size(kmeans_clusters_new, 1)): plt.plot(kmeans_clusters_new[:, ii], lw=4, label=str(ii)) plt.locator_params(axis='y', nbins=4) ax1.set(xlabel="Time (seconds)", ylabel="a.u") ax1.legend(prop={'size': 14}, loc='center left', bbox_to_anchor=(1, 0.5), ncol=1, fancybox=True, shadow=True) plt.title(plot_title, fontsize=14) plt.ylim((min(kmeans_clusters_new) - 0.0001, max(kmeans_clusters_new) + 0.0001)) plt.xlim((0, size(kmeans_clusters_new, 0))) plt.axhline(y=0, linestyle='-', color='k', linewidth=1) self.plot_vertical_lines_onset() self.plot_vertical_lines_offset() self.plot_stimulus_patch(ax1) return clrs_cmap