def plot_res(self, var, xname="time steps", ynames=None, title=None, hline=1, anom=1): if ynames is None: ynames = [""] * 4 if title is None: title = self.p["version"] # Preprocessing if "exp_ht" in var: res["exp_ht"][res["exp_ht"] == 0.0] = np.nan if "S" in self.A_version: thresh = self.p["t_thresh"] elif "T" in self.A_version: thresh = self.p["x_thresh"] elif "eng" in self.A_version: thresh = (self.p["e_high"] - self.p["e_low"]) / 2 num_plots = len(var) for i, v in enumerate(var): if type(v) == str: var[i] = getattr(self, "res")[v] if num_plots == 1: plt.figure() plt.plot(var[0]) plt.title(title) if anom == 1: for x in self.res["anomalies"]: plt.axvline(x, ymin=0.25, color="r") elif num_plots == 2: plot_2x1(var[0], var[1], ynames[:2], xname, main_title=title) if hline == 1: plt.hlines(-thresh, 0, self.res["ht"].shape[0], linestyles="dashed") plt.hlines(+thresh, 0, self.res["ht"].shape[0], linestyles="dashed") plt.ylim(-2 * thresh, 2 * thresh) if anom == 1: f = plt.gcf() for ax in f.axes[:-1]: for x in self.res["anomalies"]: ax.axvline(x, ymin=0.25, color="r") elif num_plots == 3: plot_3x1(var[0], var[1], var[2], ynames[:3], xname, main_title=title) if hline == 1: plt.hlines(-thresh, 0, self.res["ht"].shape[0], linestyles="dashed") plt.hlines(+thresh, 0, self.res["ht"].shape[0], linestyles="dashed") plt.ylim(-2 * thresh, 2 * thresh) if anom == 1: f = plt.gcf() for ax in f.axes[:-1]: for x in self.res["anomalies"]: ax.axvline(x, ymin=0.25, color="r") elif num_plots == 4: plot_4x1(var[0], var[1], var[2], var[3], ynames[:4], xname, main_title=title) plt.title(title) if hline == 1: plt.hlines(-thresh, 0, self.res["ht"].shape[0], linestyles="dashed") plt.hlines(+thresh, 0, self.res["ht"].shape[0], linestyles="dashed") plt.ylim(-2 * thresh, 2 * thresh) if anom == 1: f = plt.gcf() for ax in f.axes[:-1]: for x in self.res["anomalies"]: ax.axvline(x, ymin=0.25, color="r")
def plot_res(self, var, xname = 'Time Steps', ynames = None, title = None, hline= 1, anom = 1): """Plots each of the elements given in var. var = list of variables. Maximum = 4. if string, will look for them in self.res structure hline = whether to plot threshold values on final plot. anom = whether to plot anomalous time ticks. """ if ynames is None: ynames = ['']*4 if title is None: title = (self.p['version']) if 'SRE' in self.A_version: thresh = self.p['t_thresh'] num_plots = len(var) for i, v in enumerate(var): if type(v) == str : var[i] = getattr(self, 'res')[v] if num_plots == 1: plt.figure() plt.plot(var[0]) plt.title(title) if anom == 1: for x in self.res['anomalies']: plt.axvline(x, ymin=0.9, color='r') elif num_plots == 2: plot_2x1(var[0], var[1], ynames[:2], xname, main_title = title) if hline == 1: plt.hlines(-thresh, 0, self.res['ht'].shape[0], linestyles = 'dashed') plt.hlines(+thresh, 0, self.res['ht'].shape[0], linestyles = 'dashed') plt.ylim(-3*thresh,3*thresh) if anom == 1: f = plt.gcf() for ax in f.axes[:-1]: for x in self.res['anomalies']: ax.axvline(x, ymin=0.9, color='r') elif num_plots == 3: plot_3x1(var[0], var[1], var[2], ynames[:3] , xname, main_title = title) if hline == 1: plt.hlines(-thresh, 0, self.res['ht'].shape[0], linestyles = 'dashed') plt.hlines(+thresh, 0, self.res['ht'].shape[0], linestyles = 'dashed') plt.ylim(-3*thresh,3*thresh) if anom == 1: f = plt.gcf() for ax in f.axes[:-1]: for x in self.res['anomalies']: ax.axvline(x, ymin=0.9, color='r') elif num_plots == 4: plot_4x1(var[0], var[1], var[2], var[3], ynames[:4], xname, main_title = title) plt.title(title) if hline == 1: plt.hlines(-thresh, 0, self.res['ht'].shape[0], linestyles = 'dashed') plt.hlines(+thresh, 0, self.res['ht'].shape[0], linestyles = 'dashed') plt.ylim(-3*thresh,3*thresh) if anom == 1: f = plt.gcf() for ax in f.axes[:-1]: for x in self.res['anomalies']: ax.axvline(x, ymin=0.9, color='r') plt.draw()