def new_window(self, name=None, title=None, is_image=False): """Creates a new window and returns the index into the **windows** list for the new window. """ new_win = PlotWindow( is_image=is_image, size=(self.prefs.window_width, self.prefs.window_height), bgcolor=self.prefs.bgcolor, image_default_origin=self.prefs.image_default_origin, ) new_win.data = self.data new_win.get_container().data = self.data new_win.session = self if title is not None: new_win.set_title(title) elif name != None: new_win.set_title(name) else: new_win.set_title(self.prefs.default_window_name) self.windows.append(new_win) if name != None: self.window_map[name] = new_win return len(self.windows) - 1
def show_plot_window(self): """Creates the main window (EEG and FFT plots) from plot_window.py. """ self.plot_window = QtWidgets.QMainWindow() self.ui = PlotWindow() self.ui.setup_ui(self.plot_window) self.plot_window.setWindowFlags(QtCore.Qt.Window) self.plot_window.show() app.aboutToQuit.connect(self.close_threads)
def create_plot_types(names): for name in names: fname = '{}_plot.png'.format(name) print("*** creating figure {!r} for type {!r} ***".format(fname, name)) plot = all_examples[name]() window = PlotWindow(plot=plot) window.edit_traits() save_plot(window.container, fname)
def show(self): """ Creates and displays a plot window, or activates it (gives it focus) if it has already been created. """ if self._window and not self._window.has_exit: self._window.activate() else: self._win_args['visible'] = True self.axes.reset_resources() self._window = PlotWindow(self, **self._win_args)
def __init__(self, config, out_file_name, parent=None): super(ViewPSD, self).__init__(parent) self.config = config self.out_file_name = out_file_name self.plot_window = PlotWindow() self.plot_window.closed.connect(self.stop_view_psd) self.plot_window.show() self.plot_flg = False self.plot_ready[list].connect(self.plot)
def plot_pixel_sums(self, axis, label): plot = PlotWindow(f'{self.spec.id} {label} Sum') plt.sca(plot.axis) science = self.spec.science.sum(axis=axis) contamination = self.spec.contamination.sum(axis=axis) plt.plot(contamination, alpha=0.6, label='Contamination') plt.plot(science + contamination, alpha=0.6, label='Original') plt.plot(science, label='Decontaminated') plt.title(f'Object ID: {self.spec.id}') plt.xlabel(f'Pixel {label}') plt.ylabel(f'{label} Sum') plt.legend() plt.draw() plot.show() plot.adjustSize() plt.close()
def save(self, outfile=None, format='', size=(600, 500)): self.outfile = outfile self.format = format self.size = size self.screenshot_requested = True if not self._plot._window or self._plot._window.has_exit: self._plot._win_args['visible'] = False self._plot._win_args['width'] = size[0] self._plot._win_args['height'] = size[1] self._plot.axes.reset_resources() self._plot._window = PlotWindow(self._plot, **self._plot._win_args) self.invisibleMode = True if self.outfile is None: self.outfile = self._create_unique_path() print(self.outfile)
def show_spec_layer(self, title, data): plot = PlotWindow(title) plt.sca(plot.axis) plt.imshow(data, origin='lower') plt.subplots_adjust(top=0.975, bottom=0.025, left=0.025, right=0.975) plt.draw() plot.setWindowFlag(Qt.WindowStaysOnTopHint, False) plot.show() padding = 32 display = QApplication.desktop() current_screen = display.screenNumber(self.view) geom = display.screenGeometry(current_screen) width = geom.width() - 2 * padding height = geom.height() - 2 * padding plot.setGeometry(geom.left() + padding, geom.top() + padding, width, height) plt.close()
def plotResults(directory): np.set_printoptions(linewidth=150) plt.rc('text', usetex=True) plt.rc('font', family='serif') global xtitles, vtitles, etitles, imu_titles, colors, data, pw, plotCov xtitles = ['$p_x$', '$p_y$', '$p_z$', '$q_w$', '$q_x$', '$q_y$', '$q_z$'] vtitles = ['$v_x$', '$v_y$', '$v_z$'] etitles = ['$\phi$', r'$\theta$', '$\psi$'] imu_titles = [ r"$acc_x$", r"$acc_y$", r"$acc_z$", r"$\omega_x$", r"$\omega_y$", r"$\omega_z$" ] colors = [ '#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf' ] plotCov = True data = Log(directory) pw = PlotWindow() plotPosition() plotPosition2d() plotVelocity() plotAttitude() plotEuler() plotLla() plotIMU() plotImuBias() plotZVRes() plotBaroRes() plotRangeRes() plotGnssRes() pw.show()
def show_all_layers(self): title = f'All Layers of {self.spec.id}' horizontal = self.rect().width() > self.rect().height() subplot_grid_shape = (7, 1) if horizontal else (1, 7) plot = PlotWindow(title, shape=subplot_grid_shape) plt.sca(plot.axis[0]) plt.imshow(self.spec.contamination + self.spec.science, origin='lower') plt.title('Original') plt.draw() plt.sca(plot.axis[1]) plt.imshow(self.spec.contamination, origin='lower') plt.title('Contamination') plt.draw() plt.sca(plot.axis[2]) plt.imshow(self.spec.science, origin='lower') plt.title('Decontaminated') plt.draw() plt.sca(plot.axis[3]) if self.model is not None: plt.imshow(self.model, origin='lower') plt.title('Model') else: plt.title('N/A') plt.draw() plt.sca(plot.axis[4]) if self.model is not None: plt.imshow(self.spec.science - self.model, origin='lower') plt.title('Residual') else: plt.title('N/A') plt.draw() plt.sca(plot.axis[5]) plt.imshow(self.spec.variance, origin='lower') plt.title('Variance') plt.draw() plt.sca(plot.axis[6]) data = (flag['ZERO'] & self.spec.mask) == flag['ZERO'] plt.imshow(data, origin='lower') plt.title('Zeroth Orders') plt.draw() if horizontal: plt.subplots_adjust(top=0.97, bottom=0.025, left=0.025, right=0.975, hspace=0, wspace=0) else: plt.subplots_adjust(top=0.9, bottom=0.03, left=0.025, right=0.975, hspace=0, wspace=0) plt.draw() plot.setWindowFlag(Qt.WindowStaysOnTopHint, False) plot.show() padding = 50 display = QApplication.desktop() current_screen = display.screenNumber(self.view) geom = display.screenGeometry(current_screen) width = geom.width() - 2 * padding height = geom.height() - 2 * padding plot.setGeometry(geom.left() + padding, geom.top() + padding, width, height) plt.close()
def _plot(self, dither, detector): if self._data_series == 0: return plot = PlotWindow(f"object {self._object_id} detector: {dither}.{detector}") spec = self._inspector.collection.get_spectrum(dither, detector, self._object_id) dispersion_axis = spec.solution.dispersion_orientation() plot_flux = self._y_type == PlotSelector.Y_FLUX plot_wavelength = self._x_type == PlotSelector.X_WAV if dispersion_axis == 0: pixels = spec.x_offset + np.arange(0, spec.science.shape[1]) wavelengths = spec.solution.compute_wavelength(pixels) else: pixels = spec.y_offset + np.arange(0, spec.science.shape[0]) wavelengths = spec.solution.compute_wavelength(pixels) min_wav, max_wav = 12400, 18600 short_wav_end = np.argmin(np.fabs(wavelengths - min_wav)) long_wav_end = np.argmin(np.fabs(wavelengths - max_wav)) i_min = min(short_wav_end, long_wav_end) i_max = max(short_wav_end, long_wav_end) x_values = wavelengths[i_min: i_max] if plot_wavelength else pixels[i_min: i_max] # determine and set the limits of the x-axis if plot_wavelength and plot_flux: plot.axis.set_xlim((min_wav, max_wav)) elif plot_flux and not plot_wavelength: short_wav_end = np.argmin(np.fabs(wavelengths - min_wav)) long_wav_end = np.argmin(np.fabs(wavelengths - max_wav)) x_min = min(pixels[short_wav_end], pixels[long_wav_end]) x_max = max(pixels[short_wav_end], pixels[long_wav_end]) plot.axis.set_xlim((x_min, x_max)) zeroth_mask = np.sum(spec.mask & flag['ZERO'], axis=dispersion_axis) if self._data_series & PlotSelector.S_ORIG == PlotSelector.S_ORIG: if plot_flux: uncalibrated = np.sum(spec.science + spec.contamination, axis=dispersion_axis) y_values = self._calibrate_spectrum(dither, uncalibrated, wavelengths) else: y_values = np.sum(spec.science + spec.contamination, axis=dispersion_axis) y_values = np.ma.masked_where(zeroth_mask != 0, y_values) plot.axis.plot(x_values, y_values[i_min: i_max], label='original spectrum', color='k', linewidth=0.5, alpha=0.7) if self._data_series & PlotSelector.S_CONTAM == PlotSelector.S_CONTAM: if plot_flux: y_values = self._calibrate_spectrum(dither, spec.contamination.sum(dispersion_axis), wavelengths) else: y_values = spec.contamination.sum(dispersion_axis) plot.axis.plot(x_values, y_values[i_min: i_max], label='contamination', color='g', linewidth=0.75, alpha=0.8) if self._data_series & PlotSelector.S_DECON == PlotSelector.S_DECON: if plot_flux: y_values_unmasked = self._calibrate_spectrum(dither, spec.science.sum(dispersion_axis), wavelengths) else: y_values_unmasked = spec.science.sum(dispersion_axis) y_values = np.ma.masked_where(zeroth_mask != 0, y_values_unmasked) plot.axis.plot(x_values, y_values[i_min: i_max], label='decontaminated spectrum', color='b', linewidth=0.9) if self._data_series & PlotSelector.S_MODEL == PlotSelector.S_MODEL: model = self._inspector.collection.get_model(dither, detector, self._object_id, order=1) if model is not None: if plot_flux: y_values = self._calibrate_spectrum(dither, model.pixels.sum(dispersion_axis), wavelengths) else: y_values = model.pixels.sum(dispersion_axis) plot.axis.plot(x_values, y_values[i_min: i_max], label='model spectrum', color='r', linewidth=0.9, alpha=0.9) # plot the J and H band fluxes if the plot shows flux vs wavelength if plot_wavelength and plot_flux: info = self._inspector.location_tables.get_info(self._object_id) j_microjansky = utils.mag_to_fnu(info.jmag, zero_point=22) h_microjansky = utils.mag_to_fnu(info.hmag, zero_point=22) j_fnu = utils.mjy_to_angstrom(j_microjansky, J_WAV) h_fnu = utils.mjy_to_angstrom(h_microjansky, H_WAV) plot.axis.scatter(J_WAV, j_fnu, color='r', label='J and H band fluxes') plot.axis.scatter(H_WAV, h_fnu, color='r') x_label = r'Wavelength $\rm (\AA)$' if self._x_type == PlotSelector.X_WAV else 'Pixel' y_label = r'Flux ($\rm erg/s/cm^2/\AA$)' if self._y_type == PlotSelector.Y_FLUX else 'Electrons / second' plot.axis.set_xlabel(x_label) plot.axis.set_ylabel(y_label) plot.axis.legend() # set the descriptor; a string in the format: id.dither.detector.data_series.y_type.x_type plot.descriptor = f'{self._object_id}.{dither}.{detector}.{self._data_series}.{self._y_type}.{self._x_type}' return plot
def addGraph(self): self.parent.readCfg(self.parent.config_path, last=False) self.layout.addWidget(PlotWindow(self)) self.layout.addWidget(self.button_add_graph)
'scatter': get_scatter_plot, 'cmap_scatter': get_cmap_scatter_plot, 'vsize_scatter': get_variable_size_scatter_plot, 'jitter': get_jitter_plot, 'candle': get_candle_plot, 'errorbar': get_errorbar_plot, 'filled_line': get_filled_line_plot, 'image': get_image_plot, 'image_from_file': get_image_from_file, 'cmap_image': get_cmap_image_plot, 'contour_line': get_contour_line_plot, 'contour_poly': get_contour_poly_plot, 'polygon': get_polygon_plot, 'bar': get_bar_plot, 'quiver': get_quiver_plot, 'polar': get_polar_plot, 'multiline': get_multiline_plot, } if __name__ == '__main__': name = 'line' factory_func = all_examples[name] plot = factory_func() window = PlotWindow(plot=plot) ui = window.edit_traits() filename = '{}_plot.png'.format(name) save_plot(window.container, filename)
def __init__(self): super(MainWindow, self).__init__() self.setupUi(self) self.setWindowTitle("USRP B210 信号采样") self.setWindowIcon(QIcon("signal_app_24.png")) self.resize(1280, 720) self.plot_win = PlotWindow() # qss = "QWidget#MainWindow{background-color:red;}" # qss = "QWidget#MainWindow{border-image:url(signal_app_24.png);}" # self.setStyleSheet(qss) self.home_dir = pjoin(os.path.expanduser("~"), ".uhd_ui") self.config_path = pjoin(self.home_dir, "config.json") self.CONFIG = {} self.config = Config() self.config_keys = [ "gnu_radio_path", "save_path", "fc", "fs", "stop_fc", "sample_interval", "sample_nums", "sample_times" ] self.view_spec_config = Config() self.view_spec_config.save_path = self.home_dir self.view_spec_config.sample_times = 1 self.view_spec_config.sample_nums = 1 * 1024 * 1024 self.sample_thread = None # SampleThread() self.initial() self.save_path_btn.clicked.connect(self.open_folder) self.gnu_radio_btn.clicked.connect(self.open_gnu_folder) self.ok_btn.clicked.connect(self.sample_thread_start) self.ok_btn.setToolTip("开始采集信号") self.plot_btn.clicked.connect(self.plot_psd_start) self.plot_win.closed.connect(self.plot_psd_stop) self.stop_btn.setEnabled(False) self.stop_btn.setToolTip("停止当前信号采样") self.stop_btn.clicked.connect(self.stop_current_sampling) self.advance_groupBox.hide() self.advance_mode = False self.advance_mode_btn.setText("打开高级模式") self.advance_mode_btn.clicked.connect(self.set_advance_mode) self.gnu_radio_path_edit.textChanged[str].connect( self.new_gnu_radio_path) self.save_path_edit.textChanged[str].connect(self.new_save_path) self.fc_spinBox.valueChanged[int].connect(self.new_fc_val) self.fc_comboBox.currentIndexChanged[int].connect(self.new_fc_cbox) self.stop_fc_spinBox.valueChanged[int].connect(self.new_stop_fc_val) self.stop_fc_comboBox.currentIndexChanged[int].connect( self.new_stop_fc_cbox) self.fs_spinBox.valueChanged[int].connect(self.new_fs_val) self.fs_comboBox.currentIndexChanged[int].connect(self.new_fs_cbox) self.sample_interval_spinBox.valueChanged[int].connect( self.new_sample_interval_val) self.sample_interval_comboBox.currentIndexChanged[int].connect( self.new_sample_interval_cbox) self.sample_nums_spinBox.valueChanged[int].connect( self.new_n_sample_val) self.sample_nums_comboBox.currentIndexChanged[int].connect( self.new_n_sample_cbox) self.sample_times_spinBox.valueChanged[int].connect( self.new_sample_times) self.config_changed.connect(self.update_config)