Skip to content

Commit bc2e279

Browse files
authored
Merge pull request #160 from samcunliffe/guard-against-64
Test to guard against styling side-effects.
2 parents 04383e0 + aede1f8 commit bc2e279

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Loading

Diff for: src/napari_matplotlib/tests/test_theme.py

+30
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,33 @@ def test_titles_respect_theme(
8888

8989
assert ax.xaxis.label.get_color() == expected_text_colour
9090
assert ax.yaxis.label.get_color() == expected_text_colour
91+
92+
93+
@pytest.mark.mpl_image_compare
94+
def test_no_theme_side_effects(make_napari_viewer):
95+
"""Ensure that napari-matplotlib doesn't pollute the globally set style.
96+
97+
A MWE to guard aganst issue matplotlib/#64. Should always reproduce a plot
98+
with the default matplotlib style.
99+
"""
100+
import matplotlib.pyplot as plt
101+
102+
np.random.seed(12345)
103+
104+
# should not affect global matplotlib plot style
105+
viewer = make_napari_viewer()
106+
viewer.theme = "dark"
107+
NapariMPLWidget(viewer)
108+
109+
# some plotting unrelated to napari-matplotlib
110+
normal_dist = np.random.normal(size=1000)
111+
unrelated_figure, ax = plt.subplots()
112+
ax.hist(normal_dist, bins=100)
113+
ax.set_xlabel("something unrelated to napari (x)")
114+
ax.set_ylabel("something unrelated to napari (y)")
115+
ax.set_title(
116+
"this plot style should not change with napari styles or themes"
117+
)
118+
unrelated_figure.tight_layout()
119+
120+
return unrelated_figure

0 commit comments

Comments
 (0)