diff --git a/conda.recipe/meta.yaml b/conda.recipe/meta.yaml index 1f2a511e4..f992301c8 100644 --- a/conda.recipe/meta.yaml +++ b/conda.recipe/meta.yaml @@ -23,9 +23,7 @@ requirements: - python - fabio - hexrd=={{ hexrd_version }} - # We have some issue removing artists in matplotlib 3.10 - # Fix the matplotlib version until that is resolved. - - matplotlib-base<3.10 + - matplotlib-base - Pillow - pyhdf # This next one is needed to fix the app name on Mac diff --git a/hexrdgui/image_canvas.py b/hexrdgui/image_canvas.py index 3b26c2d03..02b36c2af 100644 --- a/hexrdgui/image_canvas.py +++ b/hexrdgui/image_canvas.py @@ -6,6 +6,7 @@ from PySide6.QtCore import QThreadPool, QTimer, Signal, Qt from PySide6.QtWidgets import QFileDialog, QMessageBox, QProgressDialog +from matplotlib.artist import Artist from matplotlib.axes import Axes from matplotlib.backends.backend_qtagg import FigureCanvas from matplotlib.figure import Figure @@ -187,10 +188,10 @@ def clear(self): self.clear_figure() def clear_figure(self): + self.remove_all_overlay_artists() self.figure.clear() self.raw_axes.clear() self.axes_images.clear() - self.remove_all_overlay_artists() self.clear_azimuthal_integral_axis() self.mode = None @@ -768,7 +769,7 @@ def update_overlays(self): def clear_detector_borders(self): while self.cached_detector_borders: - self.cached_detector_borders.pop(0).remove() + _safe_remove_artist(self.cached_detector_borders.pop(0)) self.draw_idle() @@ -792,7 +793,7 @@ def draw_detector_borders(self): def clear_stereo_border_artists(self): while self.stereo_border_artists: - self.stereo_border_artists.pop(0).remove() + _safe_remove_artist(self.stereo_border_artists.pop(0)) self.draw_idle() @@ -2222,3 +2223,14 @@ def to_stereo(xys, panel, iviewer): raise Exception(f'Unknown mode: {mode}') return funcs[mode] + + +def _safe_remove_artist(artist: Artist): + # Starting in matplotlib 3.10, we cannot remove artists from a figure + # that has already been cleared. I don't know of any easy way to check + # if the axis has been cleared, though, so for now, we just try to + # remove the artist and ignore the relevant exception if it occurs. + try: + artist.remove() + except NotImplementedError: + pass diff --git a/setup.py b/setup.py index 829d52740..c8491b335 100644 --- a/setup.py +++ b/setup.py @@ -6,9 +6,7 @@ install_reqs = [ 'hexrd', 'fabio>=0.11', - # We have some issue removing artists in matplotlib 3.10 - # Fix the matplotlib version until that is resolved. - 'matplotlib<3.10', + 'matplotlib', 'Pillow', # PySide 6.8.0 is causing segmentation faults in the testing # Keep this version downgraded until that is fixed.