diff --git a/src/napari_matplotlib/base.py b/src/napari_matplotlib/base.py index a9528a48..b69d0310 100644 --- a/src/napari_matplotlib/base.py +++ b/src/napari_matplotlib/base.py @@ -48,7 +48,6 @@ def __init__(self, napari_viewer: napari.viewer.Viewer): self.viewer = napari_viewer self.canvas = FigureCanvas() - self.canvas.widget = self self.canvas.figure.patch.set_facecolor("none") self.canvas.figure.set_layout_engine("constrained") diff --git a/src/napari_matplotlib/tests/test_histogram.py b/src/napari_matplotlib/tests/test_histogram.py index 6468a8a7..fa463642 100644 --- a/src/napari_matplotlib/tests/test_histogram.py +++ b/src/napari_matplotlib/tests/test_histogram.py @@ -1,3 +1,5 @@ +from copy import deepcopy + import pytest from napari_matplotlib import HistogramWidget @@ -9,4 +11,6 @@ def test_example_q_widget(make_napari_viewer, astronaut_data): viewer = make_napari_viewer() viewer.add_image(astronaut_data[0], **astronaut_data[1]) fig = HistogramWidget(viewer).figure - return fig + # Need to return a copy, as original figure is too eagerley garbage + # collected by the widget + return deepcopy(fig) diff --git a/src/napari_matplotlib/tests/test_slice.py b/src/napari_matplotlib/tests/test_slice.py index d439d90d..9905ad85 100644 --- a/src/napari_matplotlib/tests/test_slice.py +++ b/src/napari_matplotlib/tests/test_slice.py @@ -1,3 +1,5 @@ +from copy import deepcopy + import pytest from napari_matplotlib import SliceWidget @@ -8,4 +10,6 @@ def test_slice(make_napari_viewer, brain_data): viewer = make_napari_viewer() viewer.add_image(brain_data[0], **brain_data[1]) fig = SliceWidget(viewer).figure - return fig + # Need to return a copy, as original figure is too eagerley garbage + # collected by the widget + return deepcopy(fig)