diff --git a/mantidimaging/gui/windows/spectrum_viewer/spectrum_widget.py b/mantidimaging/gui/windows/spectrum_viewer/spectrum_widget.py index e9d0da14331..f7ff2cd6cf4 100644 --- a/mantidimaging/gui/windows/spectrum_viewer/spectrum_widget.py +++ b/mantidimaging/gui/windows/spectrum_viewer/spectrum_widget.py @@ -87,7 +87,7 @@ def __init__(self) -> None: self.nextRow() self.spectrum = self.addPlot() - self.spectrum_data_dict: dict[str, np.ndarray] = {} + self.spectrum_data_dict: dict[str, np.ndarray | None] = {} self.nextRow() self._tof_range_label = self.addLabel() diff --git a/mantidimaging/gui/windows/spectrum_viewer/view.py b/mantidimaging/gui/windows/spectrum_viewer/view.py index 778ed0d3cf0..cc34f436dc3 100644 --- a/mantidimaging/gui/windows/spectrum_viewer/view.py +++ b/mantidimaging/gui/windows/spectrum_viewer/view.py @@ -213,9 +213,7 @@ def set_spectrum(self, name: str, spectrum_data: 'np.ndarray'): self.spectrum.spectrum_data_dict[name] = spectrum_data self.spectrum.spectrum.clearPlots() - for key, value in self.spectrum.spectrum_data_dict.items(): - if key in self.spectrum.roi_dict: - self.spectrum.spectrum.plot(value, name=key, pen=self.spectrum.roi_dict[key].colour) + self.show_visible_spectrums() def clear(self) -> None: self.spectrum.spectrum_data_dict = {} @@ -256,14 +254,15 @@ def set_roi_alpha(self, alpha: float, roi_name: str) -> None: """ self.spectrum.set_roi_alpha(roi_name, alpha) if alpha == 0: - self.spectrum.spectrum_data_dict[roi_name] = np.zeros(self.spectrum.spectrum_data_dict[roi_name].shape) - else: - self.spectrum.spectrum_data_dict[roi_name] = self.spectrum.spectrum_data_dict[roi_name] + self.spectrum.spectrum_data_dict[roi_name] = None self.spectrum.spectrum.clearPlots() self.spectrum.spectrum.update() + self.show_visible_spectrums() + + def show_visible_spectrums(self): for key, value in self.spectrum.spectrum_data_dict.items(): - if key in self.spectrum.roi_dict: + if value is not None and key in self.spectrum.roi_dict: self.spectrum.spectrum.plot(value, name=key, pen=self.spectrum.roi_dict[key].colour) def add_roi_table_row(self, name: str, colour: tuple[int, int, int]):