def plot_multiple_changes_over_time(self, items_to_plot, test_percentage_lst, training_percentage, ylabel, ylim, fname, legend_loc='upper right'): for item_idx, item in enumerate(items_to_plot): test_value = self.percentage(self.results[item]['test'], test_percentage_lst[item_idx]) plt.plot(self.epoch_range, test_value, color=self.colors[item_idx][0], label=item.replace('_', ' ').replace('code switches', 'code-switches')) if 'test-std_error' in self.results[item]: test_std_error = self.results[item]['test-std_error'] lower_bound = self.percentage( self.results[item]['test'] - test_std_error, test_percentage_lst[item_idx]) upper_bound = self.percentage( self.results[item]['test'] + test_std_error, test_percentage_lst[item_idx]) plt.fill_between(self.epoch_range, lower_bound, upper_bound, facecolor=self.colors[item_idx][0], alpha=0.2) if 'training' in self.results[item]: if is_not_empty(training_percentage): training_value = self.percentage( self.results[item]['training'], training_percentage) else: training_value = self.results[item]['training'] plt.plot(self.epoch_range, training_value, color=self.colors[item_idx][1], label="%s (Training)" % item, linestyle='--') plt.xlabel('epochs') if ylabel: plt.ylabel(ylabel) plt.ylim([0, ylim]) plt.xlim(0 if fname == "performance" else 1, max( self.epoch_range)) # only start from epoch 0 for "performance" plt.xticks(np.arange(1, 30, 2)) plt.legend(loc=legend_loc, ncol=2, fancybox=True, shadow=True) plt.savefig(self.get_plot_path(fname)) plt.close()
def plot_layer_stats(self, stats): """ :param stats: dict of lists that contain means, std and labels :return: """ fig, ax = plt.subplots() ax.bar(np.arange(len(stats['labels'])), stats['means'], color='r', yerr=stats['std']) ax.set_xticklabels(stats['labels']) plt.savefig('%s/weights/summary_weights.pdf' % self.results_dir) plt.close()
def simple_bar_plot(self, fname="all_switch_points"): # prog, perfect means_prog = (3.34761383e+000, 4.15960945e+000) std_prog = (4.47782572e-001, 5.77097541e-001) means_perfect = (4.08477268e+000, 2.18383959e+000) std_perfect = (5.29089072e-001, 3.82811174e-001) n_groups = len(means_prog) fig, ax = plt.subplots() index = np.arange(n_groups) bar_width = 0.3 opacity = 0.7 error_config = {'ecolor': '0.3'} ax.bar(index, means_prog, bar_width, alpha=opacity, color='#4daf4a', yerr=std_prog, error_kw=error_config, label='auxiliary') ax.bar(index + bar_width, means_perfect, bar_width, alpha=opacity, color='#984ea3', yerr=std_perfect, error_kw=error_config, label='participle') ax.set_xticks(index + bar_width / 2) ax.set_xticklabels(('progressive', 'perfect')) ax.legend() fig.tight_layout() # make room for labels filename = '%s/%s.pdf' % (self.results_dir, fname) plt.savefig(filename) plt.close()
def plot_bar_chart_original(self, indeces, items_to_plot, legend, fname, label=None, only_last_epoch=False): index_size = np.arange(len(indeces)) fig, ax = plt.subplots() rects = [] for i, item in enumerate(items_to_plot): if not only_last_epoch: rects.append( ax.bar(index_size + (self.bar_width * i), [x[0] for x in self.cs_results[item]], self.bar_width, color=self.color_bars[i], yerr=[x[1] for x in self.cs_results[item]])) else: rects.append( ax.bar( index_size + (self.bar_width * i), item[0][-1], # self.cs_results[item][-1][0], self.bar_width, color=self.color_bars[i], yerr=item[1][-1])) if label: ax.set_ylabel(label) if self.title: ax.set_title(self.title) ax.set_xticks(index_size + self.bar_width / len(items_to_plot)) ax.set_ylim(bottom=0) if legend: ax.legend(legend) ax.set_xticklabels(indeces, rotation=55) # rotate labels to fit better plt.tight_layout() # make room for labels fname = '%s/"summary_%s_%s_cs.pdf' % (self.results_dir, self.summary_sim, fname) plt.savefig(fname) plt.close()
def plot_bar_chart(self, indeces, label, items_to_plot, legend, fname): original_idx = list(indeces) insertions = [ x for x in indeces if not x.startswith('alt') and x != 'inter-sentential' ] alternations = [x for x in indeces if x.startswith('alt')] fname = ['insertions.pdf', 'alternations.pdf'] for type, indeces in enumerate([insertions, alternations]): index_size = np.arange(len(indeces)) fig, ax = plt.subplots() rects = [] for i, item in enumerate(items_to_plot): rects.append( ax.bar(index_size + (self.bar_width * i), [ x[0] for ind, x in enumerate(self.cs_results[item]) if original_idx[ind] in indeces ], self.bar_width, color=self.color_bars[i], yerr=[ x[1] for ind, x in enumerate(self.cs_results[item]) if original_idx[ind] in indeces ])) if self.title: ax.set_title(self.title) ax.set_xticks(index_size + self.bar_width / len(items_to_plot)) ax.set_ylim(bottom=0) ax.legend(([x[0] for x in rects]), legend, loc='upper left') ax.set_xticklabels(indeces, rotation=55) # rotate labels to fit better plt.tight_layout() # make room for labels filename = '%s/%s' % (self.results_dir, fname[type]) plt.savefig(filename) plt.close()