From f72e854d234d10ad95f89a8b1ead0c8e0dce9a02 Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Thu, 6 Aug 2026 17:12:36 +0100 Subject: [PATCH 1/4] Added x-axis, y-axis, error bards, grad, and legend options --- rascal2/widgets/plot.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/rascal2/widgets/plot.py b/rascal2/widgets/plot.py index 555d6f57..7988fe55 100644 --- a/rascal2/widgets/plot.py +++ b/rascal2/widgets/plot.py @@ -591,6 +591,29 @@ def make_control_layout(self): control_layout.addWidget(QtWidgets.QLabel("Confidence Interval")) control_layout.addWidget(self.ci_param_box) + self.x_axis = QtWidgets.QComboBox() + self.x_axis.addItems(["Log", "Linear"]) + self.x_axis.currentTextChanged.connect(lambda: self.draw_plot()) + self.y_axis = QtWidgets.QComboBox() + self.y_axis.addItems(["Ref", "Q^4"]) + self.y_axis.currentTextChanged.connect(lambda: self.draw_plot()) + self.show_error_bar = QtWidgets.QCheckBox("Show Error Bars") + self.show_error_bar.setChecked(True) + self.show_error_bar.checkStateChanged.connect(lambda: self.draw_plot()) + self.show_grid = QtWidgets.QCheckBox("Show Grid") + self.show_grid.checkStateChanged.connect(lambda: self.draw_plot()) + self.show_legend = QtWidgets.QCheckBox("Show Legend") + self.show_legend.setChecked(True) + self.show_legend.checkStateChanged.connect(lambda: self.draw_plot()) + + control_layout.addWidget(QtWidgets.QLabel("X-Axis")) + control_layout.addWidget(self.x_axis) + control_layout.addWidget(QtWidgets.QLabel("Y-Axis")) + control_layout.addWidget(self.y_axis) + control_layout.addWidget(self.show_error_bar) + control_layout.addWidget(self.show_grid) + control_layout.addWidget(self.show_legend) + return control_layout def plot(self, project, results: ratapi.outputs.BayesResults): @@ -604,11 +627,17 @@ def draw_plot(self): """Plot the shaded reflectivity and SLD profiles.""" self.clear() + show_legend = self.show_legend.isChecked() ratapi.plotting.plot_ref_sld( self.project, self.results, bayes=int(self.ci_param_box.currentText().strip("%")), fig=self.figure, + linear_x=self.x_axis.currentText() == "Linear", + q4=self.y_axis.currentText() == "Q^4", + show_error_bar=self.show_error_bar.isChecked(), + show_grid=self.show_grid.isChecked(), + show_legend=show_legend, ) self.canvas.draw() From 3e1234a4e152c107206a5ef753bef3b9a0b9e3de Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Thu, 6 Aug 2026 17:29:07 +0100 Subject: [PATCH 2/4] Added slider option for Bayes plots --- rascal2/widgets/plot.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/rascal2/widgets/plot.py b/rascal2/widgets/plot.py index 7988fe55..b6c6296f 100644 --- a/rascal2/widgets/plot.py +++ b/rascal2/widgets/plot.py @@ -616,6 +616,17 @@ def make_control_layout(self): return control_layout + def make_toolbar_widget(self): + self.slider = QtWidgets.QSlider(QtCore.Qt.Orientation.Vertical) + self.slider.setTracking(False) + self.slider.setInvertedAppearance(True) + self.slider.setMinimum(0) + self.slider.setMaximum(100) + self.slider.setValue(0) + self.slider.valueChanged.connect(lambda: self.draw_plot()) + + return self.slider + def plot(self, project, results: ratapi.outputs.BayesResults): """Plot the shaded plot.""" self.project = project @@ -638,6 +649,7 @@ def draw_plot(self): show_error_bar=self.show_error_bar.isChecked(), show_grid=self.show_grid.isChecked(), show_legend=show_legend, + shift_value=self.slider.value(), ) self.canvas.draw() From a3a0d5cdce7489f0e48e6ef068a1e831e42ee97b Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Fri, 14 Aug 2026 17:07:47 +0100 Subject: [PATCH 3/4] ShadedPlotWidget now inherits RefSLDWidget to make use of existing make_control_layout --- rascal2/widgets/plot.py | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/rascal2/widgets/plot.py b/rascal2/widgets/plot.py index b6c6296f..9ab9b582 100644 --- a/rascal2/widgets/plot.py +++ b/rascal2/widgets/plot.py @@ -577,43 +577,20 @@ def plot_with_blit(self, data: ratapi.events.PlotEventData | None = None): self.blit_plot.update(self.current_plot_data) -class ShadedPlotWidget(AbstractPlotWidget): +class ShadedPlotWidget(RefSLDWidget): """Widget for plotting a contour plot of two parameters.""" def make_control_layout(self): - control_layout = QtWidgets.QVBoxLayout() + control_layout = super().make_control_layout() self.ci_param_box = QtWidgets.QComboBox(self) self.ci_param_box.addItems(["65%", "95%"]) - self.ci_param_box.currentTextChanged.connect(lambda: self.draw_plot()) + self.ci_param_box.currentTextChanged.connect(self.handle_control_changed) control_layout.addWidget(self.result_summary) control_layout.addWidget(QtWidgets.QLabel("Confidence Interval")) control_layout.addWidget(self.ci_param_box) - self.x_axis = QtWidgets.QComboBox() - self.x_axis.addItems(["Log", "Linear"]) - self.x_axis.currentTextChanged.connect(lambda: self.draw_plot()) - self.y_axis = QtWidgets.QComboBox() - self.y_axis.addItems(["Ref", "Q^4"]) - self.y_axis.currentTextChanged.connect(lambda: self.draw_plot()) - self.show_error_bar = QtWidgets.QCheckBox("Show Error Bars") - self.show_error_bar.setChecked(True) - self.show_error_bar.checkStateChanged.connect(lambda: self.draw_plot()) - self.show_grid = QtWidgets.QCheckBox("Show Grid") - self.show_grid.checkStateChanged.connect(lambda: self.draw_plot()) - self.show_legend = QtWidgets.QCheckBox("Show Legend") - self.show_legend.setChecked(True) - self.show_legend.checkStateChanged.connect(lambda: self.draw_plot()) - - control_layout.addWidget(QtWidgets.QLabel("X-Axis")) - control_layout.addWidget(self.x_axis) - control_layout.addWidget(QtWidgets.QLabel("Y-Axis")) - control_layout.addWidget(self.y_axis) - control_layout.addWidget(self.show_error_bar) - control_layout.addWidget(self.show_grid) - control_layout.addWidget(self.show_legend) - return control_layout def make_toolbar_widget(self): @@ -623,7 +600,7 @@ def make_toolbar_widget(self): self.slider.setMinimum(0) self.slider.setMaximum(100) self.slider.setValue(0) - self.slider.valueChanged.connect(lambda: self.draw_plot()) + self.slider.valueChanged.connect(self.handle_control_changed) return self.slider @@ -632,9 +609,9 @@ def plot(self, project, results: ratapi.outputs.BayesResults): self.project = project self.results = results - self.draw_plot() + self.handle_control_changed() - def draw_plot(self): + def handle_control_changed(self): """Plot the shaded reflectivity and SLD profiles.""" self.clear() From 5a4b1a4c12424cc84fe6b6cebe3ea7cc776ad8b3 Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Mon, 17 Aug 2026 14:40:40 +0100 Subject: [PATCH 4/4] initial plot settings in Bayes plots are taken from main window --- rascal2/widgets/plot.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/rascal2/widgets/plot.py b/rascal2/widgets/plot.py index 9ab9b582..5a4d90f9 100644 --- a/rascal2/widgets/plot.py +++ b/rascal2/widgets/plot.py @@ -62,7 +62,7 @@ def plot_with_blit(self, event: ratapi.events.PlotEventData): self.reflectivity_plot.plot_with_blit(event) def show_bayes_plots(self): - bayes_plots = BayesPlotsDialog(self.parent) + bayes_plots = BayesPlotsDialog(self.parent, self.reflectivity_plot.get_current_plot_settings()) bayes_plots.exec() def clear(self): @@ -73,7 +73,7 @@ def clear(self): class BayesPlotsDialog(QtWidgets.QDialog): """The modal dialog for the Bayes plots.""" - def __init__(self, parent): + def __init__(self, parent, initial_plot_settings: list): super().__init__(parent) self.parent = parent self.resize_timer = 0 @@ -94,6 +94,8 @@ def __init__(self, parent): for plot_type, plot_widget in plots.items(): self.add_tab(plot_type, plot_widget) + self.plot_tabs.widget(0).set_plot_settings(initial_plot_settings) + self.sync_and_update_model() self.plot_tabs.addTab(self.create_confidence_table(), "Parameter values") layout.addWidget(self.plot_tabs) @@ -455,6 +457,18 @@ def make_figure(self) -> matplotlib.figure.Figure: return figure + def get_current_plot_settings(self): + plot_settings = [ + self.x_axis.currentText(), + self.y_axis.currentText(), + self.show_error_bar.checkState(), + self.show_grid.checkState(), + self.show_legend.checkState(), + self.slider.value(), + ] + + return plot_settings + def handle_control_changed(self): if self.blit_plot is None: self.plot_event() @@ -604,6 +618,14 @@ def make_toolbar_widget(self): return self.slider + def set_plot_settings(self, plot_settings: list): + self.x_axis.setCurrentText(plot_settings[0]) + self.y_axis.setCurrentText(plot_settings[1]) + self.show_error_bar.setCheckState(plot_settings[2]) + self.show_grid.setCheckState(plot_settings[3]) + self.show_legend.setCheckState(plot_settings[4]) + self.slider.setValue(plot_settings[5]) + def plot(self, project, results: ratapi.outputs.BayesResults): """Plot the shaded plot.""" self.project = project