Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5fd8418

Browse filesBrowse files
committed
Clean out old styling code
1 parent e9853fb commit 5fd8418
Copy full SHA for 5fd8418

File tree

9 files changed

+5
-128
lines changed
Filter options

9 files changed

+5
-128
lines changed

‎MANIFEST.in

Copy file name to clipboardExpand all lines: MANIFEST.in
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
include LICENSE
22
include README.md
3-
recursive-include * *.mplstyle
43

54
recursive-exclude * __pycache__
65
recursive-exclude * *.py[co]

‎docs/user_guide.rst

Copy file name to clipboardExpand all lines: docs/user_guide.rst
+3-8Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ To use these:
4040

4141
Customising plots
4242
-----------------
43-
`Matplotlib style sheets <https://matplotlib.org/stable/tutorials/introductory/customizing.html#defining-your-own-style>`__ can be used to customise
44-
the plots generated by ``napari-matplotlib``.
45-
To use a custom style sheet:
46-
47-
1. Save it as ``napari-matplotlib.mplstyle``
48-
2. Put it in the Matplotlib configuration directory.
49-
The location of this directory varies on different computers,
50-
and can be found by calling :func:`matplotlib.get_configdir()`.
43+
``napari-matplotlib`` uses colours from the current napari theme to customise the
44+
Matplotlib plots. See `the example on creating a new napari theme
45+
<https://napari.org/stable/gallery/new_theme.html>`_ for a helpful guide.

‎pyproject.toml

Copy file name to clipboardExpand all lines: pyproject.toml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ write_to = "src/napari_matplotlib/_version.py"
77

88
[tool.pytest.ini_options]
99
qt_api = "pyqt6"
10-
addopts = "--mpl"
10+
addopts = "--mpl --mpl-baseline-relative"
1111
filterwarnings = [
1212
"error",
1313
# Coming from vispy

‎src/napari_matplotlib/base.py

Copy file name to clipboardExpand all lines: src/napari_matplotlib/base.py
-6Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from pathlib import Path
33
from typing import Optional
44

5-
import matplotlib
65
import matplotlib.style as mplstyle
76
import napari
87
from matplotlib.backends.backend_qtagg import ( # type: ignore[attr-defined]
@@ -19,10 +18,6 @@
1918

2019
__all__ = ["BaseNapariMPLWidget", "NapariMPLWidget", "SingleAxesWidget"]
2120

22-
_CUSTOM_STYLE_PATH = (
23-
Path(matplotlib.get_configdir()) / "napari-matplotlib.mplstyle"
24-
)
25-
2621

2722
class BaseNapariMPLWidget(QWidget):
2823
"""
@@ -47,7 +42,6 @@ def __init__(
4742
):
4843
super().__init__(parent=parent)
4944
self.viewer = napari_viewer
50-
# self._mpl_style_sheet_path: Optional[Path] = None
5145
self.napari_theme_style_sheet = style_sheet_from_theme(
5246
get_theme(napari_viewer.theme, as_dict=False)
5347
)

‎src/napari_matplotlib/styles/README.md

Copy file name to clipboardExpand all lines: src/napari_matplotlib/styles/README.md
-3Lines changed: 0 additions & 3 deletions
This file was deleted.

‎src/napari_matplotlib/styles/dark.mplstyle

Copy file name to clipboardExpand all lines: src/napari_matplotlib/styles/dark.mplstyle
-12Lines changed: 0 additions & 12 deletions
This file was deleted.

‎src/napari_matplotlib/styles/light.mplstyle

Copy file name to clipboardExpand all lines: src/napari_matplotlib/styles/light.mplstyle
-12Lines changed: 0 additions & 12 deletions
This file was deleted.

‎src/napari_matplotlib/tests/data/test_theme.mplstyle

Copy file name to clipboardExpand all lines: src/napari_matplotlib/tests/data/test_theme.mplstyle
-15Lines changed: 0 additions & 15 deletions
This file was deleted.

‎src/napari_matplotlib/tests/test_theme.py

Copy file name to clipboardExpand all lines: src/napari_matplotlib/tests/test_theme.py
+1-70Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
import os
2-
import shutil
3-
from copy import deepcopy
4-
from pathlib import Path
51

6-
import matplotlib
72
import napari
83
import numpy as np
94
import pytest
10-
from matplotlib.colors import to_rgba
115

12-
from napari_matplotlib import HistogramWidget, ScatterWidget
6+
from napari_matplotlib import ScatterWidget
137
from napari_matplotlib.base import NapariMPLWidget
148

159

@@ -127,66 +121,3 @@ def test_no_theme_side_effects(make_napari_viewer):
127121
unrelated_figure.tight_layout()
128122

129123
return unrelated_figure
130-
131-
132-
@pytest.mark.mpl_image_compare
133-
def test_custom_theme(make_napari_viewer, theme_path, brain_data):
134-
viewer = make_napari_viewer()
135-
viewer.theme = "dark"
136-
137-
widget = ScatterWidget(viewer)
138-
widget.mpl_style_sheet_path = theme_path
139-
140-
viewer.add_image(brain_data[0], **brain_data[1], name="brain")
141-
viewer.add_image(
142-
brain_data[0] * -1, **brain_data[1], name="brain_reversed"
143-
)
144-
145-
viewer.layers.selection.clear()
146-
viewer.layers.selection.add(viewer.layers[0])
147-
viewer.layers.selection.add(viewer.layers[1])
148-
149-
return deepcopy(widget.figure)
150-
151-
152-
def find_mpl_stylesheet(name: str) -> Path:
153-
"""Find the built-in matplotlib stylesheet."""
154-
return Path(matplotlib.__path__[0]) / f"mpl-data/stylelib/{name}.mplstyle"
155-
156-
157-
def test_custom_stylesheet(make_napari_viewer, image_data):
158-
"""
159-
Test that a stylesheet in the current directory is given precidence.
160-
161-
Do this by copying over a stylesheet from matplotlib's built in styles,
162-
naming it correctly, and checking the colours are as expected.
163-
"""
164-
# Copy Solarize_Light2 as if it was a user-overriden stylesheet.
165-
style_sheet_path = (
166-
Path(matplotlib.get_configdir()) / "napari-matplotlib.mplstyle"
167-
)
168-
if style_sheet_path.exists():
169-
pytest.skip("Won't ovewrite existing custom style sheet.")
170-
shutil.copy(
171-
find_mpl_stylesheet("Solarize_Light2"),
172-
style_sheet_path,
173-
)
174-
175-
try:
176-
viewer = make_napari_viewer()
177-
viewer.add_image(image_data[0], **image_data[1])
178-
widget = HistogramWidget(viewer)
179-
assert widget.mpl_style_sheet_path == style_sheet_path
180-
ax = widget.figure.gca()
181-
182-
# The axes should have a light brownish grey background:
183-
assert ax.get_facecolor() == to_rgba("#eee8d5")
184-
assert ax.patch.get_facecolor() == to_rgba("#eee8d5")
185-
186-
# The figure background and axis gridlines are light yellow:
187-
assert widget.figure.patch.get_facecolor() == to_rgba("#fdf6e3")
188-
for gridline in ax.get_xgridlines() + ax.get_ygridlines():
189-
assert gridline.get_visible() is True
190-
assert gridline.get_color() == "#b0b0b0"
191-
finally:
192-
os.remove(style_sheet_path)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.