def setup_plot_spectrum_actions(self, context_menu, table): plot_spectrum_action = QAction(self.GRAPH_ICON, "Plot spectrum (values only)", self) plot_spectrum_action.triggered.connect( partial(self.presenter.action_plot_spectrum, table)) plot_spectrum_with_errors_action = QAction( self.GRAPH_ICON, "Plot spectrum (values + errors)", self) plot_spectrum_with_errors_action.triggered.connect( partial(self.presenter.action_plot_spectrum_with_errors, table)) overplot_spectrum_action = QAction(self.GRAPH_ICON, "Overplot spectrum (values only)", self) overplot_spectrum_action.triggered.connect( partial(self.presenter.action_overplot_spectrum, table)) overplot_spectrum_with_errors_action = QAction( self.GRAPH_ICON, "Overplot spectrum (values + errors)", self) overplot_spectrum_with_errors_action.triggered.connect( partial(self.presenter.action_overplot_spectrum_with_errors, table)) overplot_spectrum_action.setEnabled(can_overplot()) overplot_spectrum_with_errors_action.setEnabled(can_overplot()) separator = QAction(self) separator.setSeparator(True) list( map(context_menu.addAction, [ plot_spectrum_action, plot_spectrum_with_errors_action, separator, overplot_spectrum_action, overplot_spectrum_with_errors_action ]))
def _do_plot_spectrum(self, names, errors, overplot): """ Plot spectra from the selected workspaces :param names: A list of workspace names :param errors: If true then error bars will be plotted on the points :param overplot: If true then the add to the current figure if one exists and it is a compatible figure """ if overplot: compatible, error_msg = can_overplot() if not compatible: QMessageBox.warning(self, "", error_msg) return plot_from_names(names, errors, overplot)
def _do_plot_spectrum(self, names, errors, overplot): """ Plot spectra from the selected workspaces :param names: A list of workspace names :param errors: If true then error bars will be plotted on the points :param overplot: If true then the add to the current figure if one exists and it is a compatible figure """ if overplot: compatible, error_msg = can_overplot() if not compatible: QMessageBox.warning(self, "", error_msg) return plot_from_names(names, errors, overplot)
def _do_plot_bin(self, names, errors, overplot): """ Plot a single bin from the selected workspaces :param names: A list of workspace names :param errors: If true then error bars will be plotted on the points :param overplot: If true then the add to the current figure if one exists and it is a compatible figure """ if overplot: compatible, error_msg = can_overplot() if not compatible: QMessageBox.warning(self, "", error_msg) return plot_kwargs = {"axis": MantidAxType.BIN} plot(self._ads.retrieveWorkspaces(names, unrollGroups=True), errors=errors, overplot=overplot,wksp_indices=[0], plot_kwargs=plot_kwargs)
def _do_plot_1d_md(self, names, errors, overplot): """ Plot 1D IMDHistoWorlspaces :param names: list of workspace names :param errors: boolean. if true, the error bar will be plotted :param overplot: boolean. If true, then add these plots to the current figure if one exists and it is a compatible figure :return: """ if overplot: compatible, error_msg = can_overplot() if not compatible: QMessageBox.warning(self, "", error_msg) return try: plot_md_ws_from_names(names, errors, overplot) except RuntimeError as re: logger.error(str(re))
def _do_plot_spectrum(self, names, errors, overplot, advanced=False): """ Plot spectra from the selected workspaces :param names: A list of workspace names :param errors: If true then error bars will be plotted on the points :param overplot: If true then the add to the current figure if one exists and it is a compatible figure :param advanced: If true then the advanced options will be shown in the spectra selector dialog. """ if overplot: compatible, error_msg = can_overplot() if not compatible: QMessageBox.warning(self, "", error_msg) return try: plot_from_names(names, errors, overplot, advanced=advanced) except RuntimeError as re: logger.error(str(re))
def test_can_overplot_returns_false_for_active_patch_plot(self): plt.pcolormesh(np.arange(9.).reshape(3, 3)) allowed = can_overplot() self.assertFalse(allowed)
def test_can_overplot_returns_true_for_active_line_plot(self): plt.plot([1, 2]) self.assertTrue(can_overplot())
def test_can_overplot_returns_false_with_no_active_plots(self): self.assertFalse(can_overplot())
def _on_context_menu(self): """ Triggered when the context menu is about to be displayed. """ ableToOverplot = can_overplot() self.workspacewidget.setOverplotDisabled(not ableToOverplot)
def test_can_overplot_returns_false_for_active_patch_plot(self): plt.pcolormesh(np.arange(9.).reshape(3,3)) allowed, msg = can_overplot() self.assertFalse(allowed) self.assertTrue(len(msg) > 0)
def test_can_overplot_returns_true_for_active_line_plot(self): plt.plot([1, 2]) self.assertTrue(can_overplot()[0])
def test_can_overplot_returns_false_with_no_active_plots(self): self.assertFalse(can_overplot()[0])