Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 48 additions & 5 deletions rascal2/widgets/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -577,22 +591,41 @@ 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)

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(self.handle_control_changed)

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
Expand All @@ -604,14 +637,24 @@ 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,
shift_value=self.slider.value(),
)
self.canvas.draw()

def handle_control_changed(self):
self.draw_plot()


class AbstractPanelPlotWidget(AbstractPlotWidget):
"""Abstract base widget for plotting panels of parameters (corner plot, histograms, chains).
Expand Down
Loading