def _print_window(self, *args, **kwargs): """Save figure for each dataset. Parameters ---------- args The parameters sent to the plotting back end to create a hardcopy version of the plot. The first argument - if given - is taken to be the filename, and any ``#`` character in it will be replaced by the data set identifier (so that multiple files will be created). kwargs Any keyword arguments to pass to the plotting back end. """ orig_args = args for dataset in self.filter_datasets(): args = orig_args if len(args) > 0: filename = re.sub(r'#', str(dataset['id']), args[0]) args = tuple([filename]) + args[1:] if _plot_pkg == 'chips': pychips.set_current_window(dataset['id']) func = pychips.print_window elif _plot_pkg == 'pylab': plt.figure(self.ids.index(dataset['id']) + 1) func = plt.savefig else: raise ValueError('Unknown plot package') func(*args, **kwargs)
def _print_window(self, *args, **kwargs): """Save figure for each dataset. Here is the text for index.rst: In the ``print_window`` command if a filename is supplied (for saving to a set of files) it should have a ``#`` character which will be replaced by the dataset ``id`` in each case. :param args: list arguments to pass to print_window :param kwargs: named (keyword) arguments to pass to print_window :rtype: None """ orig_args = args for dataset in self.filter_datasets(): args = orig_args if len(args) > 0: filename = re.sub(r'#', str(dataset['id']), args[0]) args = tuple([filename]) + args[1:] if _plot_pkg == 'chips': pychips.set_current_window(dataset['id']) func = pychips.print_window elif _plot_pkg == 'pylab': plt.figure(self.ids.index(dataset['id']) + 1) func = plt.savefig else: raise ValueError('Unknown plot package') func(*args, **kwargs)
def _sherpa_plot(self, func, *args, **kwargs): """Call Sherpa plot ``func`` for each dataset. :param func: Sherpa plot function :param args: plot function list arguments :param kwargs: plot function named (keyword) arguments :rtype: None """ for shell in range(self.nshell): window_id = 'Shell%d' % shell try: pychips.add_window(['id', window_id]) except RuntimeError: pass # already exists new_args = args if len(args) > 0: # Try to format first arg try: new_args = tuple([args[0] % shell]) + args[1:] except TypeError: pass pychips.set_current_window(window_id) func(*new_args, **kwargs)
def select_plot(dataset, ids): """Select the plot window or figure for the given dataset. The plot for this dataset is assumed to have been created. Parameters ---------- dataset : str or int The dataset. ids : array_like The identifier array from the DataStack object. See Also -------- initialize_plot """ pychips.set_current_window(dataset['id'])
def _sherpa_plot(self, func, *args, **kwargs): """Call the Sherpa plot ``func`` for each shell. Parameters ---------- func : function reference The Sherpa plot function args The arguments for `func` kwargs Any keyword arguments for `func`. There are special keywords which are not passed on: `single_call_per_shell` is a boolean which indicates that the function is only called once per shell, and `add_shell_value` which indicates that the first argument is formatted to accept the shell value. Notes ----- This method attempts to handle the differences when using ChIPS or Matplotlib as the Sherpa plotting backend, but has not been properly tested, so there may be issues. It is known not to work when the input function is plot_fit_delchi or plot_fit_resid, at least with the Matplotlib backend. It is unclear whether this is a problem here or the Sherpa matplotlib backend. """ # Attempt to support multiple datasets per annulus. # dmap = [[] for _ in range(self.nshell)] for d in self.datasets: dmap[d['annulus']].append(d['id']) # Extract the arguments used here # special = {} for key in ['add_shell_value', 'single_call_per_shell']: val = False if key in kwargs: val = kwargs[key] del kwargs[key] special[key] = val nargs = len(args) for shell in range(self.nshell): if backend_name == 'pychips': window_id = 'Shell%d' % shell try: pychips.add_window(['id', window_id]) except RuntimeError: pychips.set_current_window(window_id) elif backend_name == 'pylab': plt.figure(shell) new_args = args if nargs > 0: if special['add_shell_value']: new_args = list(args)[:] new_args[0] = new_args[0].format(shell) # For the moment assume that if the user supplied an # argument then we use it, whatever the various # settings are. This catches errors like # dep.plot_fit('rstat') # if special['single_call_per_shell'] or nargs > 0: func(*new_args, **kwargs) else: # call it once per data set, assuming that the # overplot keyword is supported by this function # (could check this condition but leave that for now) # overplot = False for did in dmap[shell]: kwargs['overplot'] = overplot func(did, **kwargs) overplot = True