File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
src/napari_matplotlib/tests Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ from copy import deepcopy
2+
13import napari
24import numpy as np
35import pytest
@@ -88,3 +90,31 @@ def test_titles_respect_theme(
8890
8991 assert ax .xaxis .label .get_color () == expected_text_colour
9092 assert ax .yaxis .label .get_color () == expected_text_colour
93+
94+
95+ @pytest .mark .mpl_image_compare
96+ def test_no_theme_side_effects (make_napari_viewer ):
97+ """Ensure that napari-matplotlib doesn't pollute the globally set style.
98+
99+ A MWE to guard aganst issue matplotlib/#64. Should always reproduce a plot
100+ with the default matplotlib style.
101+ """
102+ import matplotlib .pyplot as plt
103+
104+ np .random .seed (12345 )
105+
106+ # should not affect global matplotlib plot style
107+ viewer = make_napari_viewer ()
108+ viewer .theme = "dark"
109+ NapariMPLWidget (viewer )
110+
111+ # some plotting unrelated to napari-matplotlib
112+ image = np .random .random ((3 , 3 ))
113+ plt .imshow (image )
114+ plt .xlabel ("something unrelated to napari (x)" )
115+ plt .ylabel ("something unrelated to napari (y)" )
116+ plt .title ("this plot style should not change with napari styles or themes" )
117+ plt .tight_layout ()
118+ unrelated_figure = plt .gcf ()
119+
120+ return deepcopy (unrelated_figure )
You can’t perform that action at this time.
0 commit comments