def to_dropbox(self, fname, dropbox_path=None, access_token=None): from haven import haven_dropbox as hd dropbox_path = '/SLS_results/' access_token = 'Z61CnS89EjIAAAAAAABJ19VZt6nlqaw5PtWEBZYBhdLbW7zDyHOYP8GDU2vA2HAI' out_fname = os.path.join(dropbox_path, fname) src_fname = os.path.join(self.savedir_base, fname) self.to_zip(src_fname) hd.upload_file_to_dropbox(src_fname, out_fname, access_token) print('saved: https://www.dropbox.com/home/%s' % out_fname)
def to_dropbox(self, fname, dropbox_path=None, access_token=None): """[summary] Parameters ---------- fname : [type] [description] dropbox_path : [type], optional [description], by default None access_token : [type], optional [description], by default None """ from haven import haven_dropbox as hd out_fname = os.path.join(dropbox_path, fname) src_fname = os.path.join(self.savedir_base, fname) self.to_zip(src_fname) hd.upload_file_to_dropbox(src_fname, out_fname, access_token) print('saved: https://www.dropbox.com/home/%s' % out_fname)
def get_plots(self, transpose=False, y_list=None, title_list=None, legend_list=None, avg_runs=0, s_epoch=0, e_epoch=None, x_name='epoch', width=8, height=6, y_log_list=(None, ), ylim_list=None, xlim_list=None, color_regard_dict=None, label_regard_dict=None, legend_fontsize=None, y_fontsize=None, x_fontsize=None, xtick_fontsize=None, ytick_fontsize=None, title_fontsize=None, linewidth=None, markersize=None, title_dict=None, y_only_first_flag=False, legend_kwargs=None, markevery=1, bar_flag=None, savedir=None, dropbox_dir=None, savedir_base=None, legend_only_first_flag=False, legend_flag=True, y_list_dict=None, marker_regard_dict=None): if not savedir_base: savedir_base = self.savedir_base exp_sublists = self.exp_sublists if transpose: ncols = len(y_list) n_plots = len(exp_sublists) else: ncols = len(exp_sublists) n_plots = len(y_list) if ylim_list is not None: if isinstance(ylim_list[0], list): ylim_list_list = ylim_list else: ylim_list_list = as_double_list(ylim_list) * n_plots if xlim_list is not None: if isinstance(xlim_list[0], list): xlim_list_list = xlim_list else: xlim_list_list = as_double_list(xlim_list) * n_plots for j in range(n_plots): fig, axs = plt.subplots(nrows=1, ncols=ncols, figsize=(ncols * width, 1 * height)) if not hasattr(axs, 'size'): axs = [axs] n_results_total = 0 for i in range(ncols): if ylim_list is not None: ylim = ylim_list_list[j][i] else: ylim = None if xlim_list is not None: xlim = xlim_list[j][i] else: xlim = None if y_only_first_flag and i > 0: ylabel_flag = False else: ylabel_flag = True if legend_only_first_flag: legend_flag = False else: legend_flag = legend_flag if transpose: y_name = y_list[i] exp_list = exp_sublists[j] else: y_name = y_list[j] exp_list = exp_sublists[i] title, n_results = plot_exp_list( axs[i], exp_list, y_name=y_name, x_name=x_name, avg_runs=avg_runs, legend_list=legend_list, s_epoch=s_epoch, e_epoch=e_epoch, y_log_list=y_log_list, title_list=title_list, ylim=ylim, xlim=xlim, color_regard_dict=color_regard_dict, label_regard_dict=label_regard_dict, legend_fontsize=legend_fontsize, y_fontsize=y_fontsize, x_fontsize=x_fontsize, xtick_fontsize=xtick_fontsize, ytick_fontsize=ytick_fontsize, title_fontsize=title_fontsize, linewidth=linewidth, markersize=markersize, title_dict=title_dict, ylabel_flag=ylabel_flag, legend_kwargs=legend_kwargs, markevery=markevery, savedir_base=savedir_base, bar_flag=bar_flag, legend_flag=legend_flag, y_list_dict=y_list_dict, marker_regard_dict=marker_regard_dict) n_results_total += n_results if n_results == 0: print('no results for plot with title %s' % title) if n_results_total == 0: plt.close() else: if legend_only_first_flag: if legend_kwargs is None: legend_kwargs = { 'bbox_to_anchor': (0, -0.25), 'ncol': 7, 'loc': 'lower center' } # plt.legend(fontsize=legend_fontsize, **legend_kwargs) # fig.subplots_adjust(top=0.9, left=0.1, right=0.9, bottom=0.12) # create some space below the plots by increasing the bottom-value # axs.flatten()[-2].legend(fontsize=legend_fontsize, **legend_kwargs) plt.legend(fontsize=legend_fontsize, **legend_kwargs) if savedir: plot_fname = os.path.join( savedir, '%s.pdf' % title.replace(' ', '')) plt.savefig(plot_fname, dpi=300, bbox_inches='tight') print('saved: %s' % plot_fname) if dropbox_dir: from haven import haven_dropbox as hd plot_fname = os.path.join(self.savedir_base, 'tmp.png') plt.savefig(plot_fname, dpi=300, bbox_inches='tight') # dropbox_dir = '/SLS_results/' access_token = 'Z61CnS89EjIAAAAAAABJ19VZt6nlqaw5PtWEBZYBhdLbW7zDyHOYP8GDU2vA2HAI' out_fname = os.path.join(dropbox_dir, '%s.png' % title.replace(' ', '')) hd.upload_file_to_dropbox(plot_fname, out_fname, access_token) print('saved: https://www.dropbox.com/home/%s' % out_fname) # plt.grid(True) # plt.tight_layout() plt.show() plt.close()