def plot_lines(self): self.clear_markers() o = self.atom if o is not None: self.figure.clear() n = sum([info.flag for info in self.plot_info ]) # number of subplots (0, 1 or 2) # map to reuse plotting routine, contains what differs between each plot map_ = [(ATOM_HEADERS[i], o.__getattribute__(ATOM_ATTR_NAMES[i])) for i in range(1, len(ATOM_HEADERS))] # number of rows and columns for each different number of subplots SL = [(1, 1), (2, 1), (2, 2), (2, 2), (3, 2), (3, 2)] i_subplot = 1 for i in range(len(map_)): y_label = map_[i][0] pi = self.plot_info[i] pi.y_vector = _y = map_[i][1] if pi.flag: if not self.flag_sort: x = o.lambda_ y = _y else: _x = np.array(o.lambda_) _y = np.array(_y) ii = np.argsort(_x) x = _x[ii] y = _y[ii] a99.format_BLB() self.figure.add_subplot(SL[n - 1][0], SL[n - 1][1], i_subplot) pi.axis = ax = self.figure.gca() ax.clear() ax.plot(x, y, 'k' + ('' if len(x) > 1 else 'x')) ax.set_xlabel('Wavelength ($\AA$)') ax.set_ylabel(y_label) # x-limits xmin, xmax = min(x), max(x) K = .02 * (xmax - xmin) ax.set_xlim([xmin - K, xmax + K]) # y-limits ymin, ymax = min(y), max(y) K = .02 * (ymax - ymin) ax.set_ylim([ymin - K, ymax + K]) i_subplot += 1 if i_subplot > 1: plt.tight_layout() self.canvas.draw() self.draw_markers()
def plot_lines(self): try: self.clear_markers() o = self.sol if o is not None: self.figure.clear() n = sum([info.flag for info in self.plot_info]) # number of subplots (0, 1 or 2) # map to reuse plotting routine, contains what differs between each plot map_ = [(SOL_HEADERS_PLOT[i], o.__getattribute__(SOL_ATTR_NAMES[i])) for i in range(1, len(SOL_HEADERS_PLOT))] i_subplot = 1 for i in range(len(map_)): y_label = map_[i][0] pi = self.plot_info[i] pi.y_vector = _y = map_[i][1] if pi.flag: if not self.flag_sort: x = o.lmbdam y = _y else: _x = np.array(o.lmbdam) _y = np.array(_y) ii = np.argsort(_x) x = _x[ii] y = _y[ii] a99.format_BLB() self.figure.add_subplot(n, 1, i_subplot) pi.axis = ax = self.figure.gca() ax.clear() ax.plot(x, y, 'k'+('' if len(x) > 1 else 'x')) ax.set_xlabel('Wavelength ($\AA$)') ax.set_ylabel(y_label) # x-limits xmin, xmax = min(x), max(x) k = .02*(xmax-xmin) ax.set_xlim([xmin-k, xmax+k]) # y-limits ymin, ymax = min(y), max(y) k = .02*(ymax-ymin) ax.set_ylim([ymin-k, ymax+k]) i_subplot += 1 if i_subplot > 1: plt.tight_layout() self.canvas.draw() self.draw_markers() except Exception as e: a99.show_error("Error drawing plots: {}".format(str(e)))
def _plot(self): attr_name = str(self.comboBoxDataField.currentText()) num_bins = int(self.spinBox.value()) v = self.f.__getattribute__(attr_name) self.figure.clear() ax = self.figure.add_subplot(111) ax.hist(v, num_bins) ax.set_xlabel(attr_name) ax.set_ylabel("counts") plt.tight_layout() a99.format_BLB() self.canvas.draw()
def _draw(self): fig = self.figure fig.clear() plt.figure(fig.number) try: a99.format_BLB() # Spectrum sp = self._spectrum if sp is not None: setup = f311.PlotSpectrumSetup() plt.plot(sp.x, sp.y, label=str(sp.title), color=_COLOR_SPECTRUM, linestyle=_LINESTYLE_SPECTRUM, linewidth=_LINEWIDTH) plt.xlabel(setup.fmt_xlabel.format(sp)) xmin, xmax, ymin, ymax, xspan, yspan = f311.calc_max_min([sp]) ymin, ymax = min(0., ymin), max(1., ymax) _T = 0.02 # fraction of extra space on left, right, top, bottom of graphics plt.xlim([xmin - xspan * _T, xmax + xspan * _T]) plt.ylim([ymin - yspan * _T, ymax + yspan * _T]) # Continuum if self._points is not None: xx, yy = zip(*self._points) plt.plot(xx, yy, c=_COLOR_LINE, linestyle=_LINESTYLE_CONTINUUM, linewidth=_LINEWIDTH) plt.plot(xx, yy, c=_COLOR_MARKER, linestyle="None", marker=_MARKER) try: fig.tight_layout() except: a99.get_python_logger().exception("WContinuum._draw()") except: a99.get_python_logger().exception("WContinuum._draw()") finally: self.canvas.draw()
ecombo.conf.flag_output_to_dir = True oo = ecombo.conf.opt # Assigns synthesis range to match atomic lines range oo.llzero, oo.llfin = fatoms2.llzero, fatoms2.llfin # Turns off hydrogen lines oo.no_h = True # Turns off molecular lines oo.no_molecules = True runnables.append(ecombo) pyfant.run_parallel(runnables) # Draws figure f = plt.figure() a99.format_BLB() for i, (title, ecombo) in enumerate(zip(MY_SPECIES, runnables)): ecombo.load_result() plt.subplot(2, 3, i + 1) f311.draw_spectra_overlapped([ecombo.result["spec"]], setup=f311.PlotSpectrumSetup( flag_xlabel=i / 3 >= 1, flag_legend=False)) plt.title(title) K = 1. a99.set_figure_size(plt.gcf(), 1300 * K, 740 * K) plt.tight_layout() plt.savefig("synthesis-atoms.png") plt.show()
def _draw(self): def _ensure_new_fig(): fig = self.figure fig.clear() plt.figure(fig.number) while True: yield enfig = _ensure_new_fig() try: a99.format_BLB() name = self._get_continuum_name() if name != self._draw_last_name: self._lose_plots() next(enfig) self._draw_last_name = name # Spectrum sp = self._spectrum if sp is not None: ######################### next(enfig) if self._plot_sp is None: self._plot_sp, = plt.plot(sp.x, sp.y, label=str(sp.title), color=_COLOR_SPECTRUM, linestyle=_LINESTYLE_SPECTRUM, linewidth=_LINEWIDTH) setup = f311.PlotSpectrumSetup() plt.xlabel(setup.fmt_xlabel.format(sp)) else: self._update_plot_data(self._plot_sp, zip(sp.x, sp.y)) xmin, xmax, ymin, ymax, xspan, yspan = f311.calc_max_min([sp]) ymin, ymax = min(0., ymin), max(1., ymax) _T = 0.02 # fraction of extra space on left, right, top, bottom of graphics plt.xlim([xmin - xspan * _T, xmax + xspan * _T]) plt.ylim([ymin - yspan * _T, ymax + yspan * _T]) # Continua cuum = self._get_continuum() if cuum is not None: points = cuum["points"] p0 = cuum["plot0"] if p0: self._update_plot_data(p0, points) self._update_plot_data(cuum["plot1"], points) else: xx, yy = self._get_xx_yy(points) ########################################## next(enfig) cuum["plot0"], = plt.plot(xx, yy, c=_COLOR_LINE, linestyle=_LINESTYLE_CONTINUUM, linewidth=_LINEWIDTH) cuum["plot1"], = plt.plot(xx, yy, c=_COLOR_MARKER, linestyle="None", marker=_MARKER) try: self.figure.tight_layout() except: a99.get_python_logger().exception("WContinua._draw()") except: a99.get_python_logger().exception("WContinua._draw()") finally: self.canvas.draw()