Skip to content

Axis labels should respect the theme (#142) and fix #96 whilst I'm at it. #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/napari_matplotlib/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def _draw(self) -> None:
isinstance(layer, self.input_layer_types) for layer in self.layers
):
self.draw()
self.apply_napari_colorscheme(self.figure.gca())
self.canvas.draw()

def clear(self) -> None:
Expand Down
Binary file modified src/napari_matplotlib/tests/baseline/test_histogram_2D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/napari_matplotlib/tests/baseline/test_histogram_3D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/napari_matplotlib/tests/baseline/test_slice_2D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/napari_matplotlib/tests/baseline/test_slice_3D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/napari_matplotlib/tests/scatter/baseline/test_scatter_2D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/napari_matplotlib/tests/scatter/baseline/test_scatter_3D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/napari_matplotlib/tests/scatter/test_scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@pytest.mark.mpl_image_compare
def test_scatter_2D(make_napari_viewer, astronaut_data):
viewer = make_napari_viewer()
viewer.theme = "light"
widget = ScatterWidget(viewer)
fig = widget.figure

Expand All @@ -28,6 +29,7 @@ def test_scatter_2D(make_napari_viewer, astronaut_data):
@pytest.mark.mpl_image_compare
def test_scatter_3D(make_napari_viewer, brain_data):
viewer = make_napari_viewer()
viewer.theme = "light"
widget = ScatterWidget(viewer)
fig = widget.figure

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@pytest.mark.mpl_image_compare
def test_features_scatter_widget_2D(make_napari_viewer):
viewer = make_napari_viewer()
viewer.theme = "light"
widget = FeaturesScatterWidget(viewer)

# make the points data
Expand Down
2 changes: 2 additions & 0 deletions src/napari_matplotlib/tests/test_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@pytest.mark.mpl_image_compare
def test_histogram_2D(make_napari_viewer, astronaut_data):
viewer = make_napari_viewer()
viewer.theme = "light"
viewer.add_image(astronaut_data[0], **astronaut_data[1])
fig = HistogramWidget(viewer).figure
# Need to return a copy, as original figure is too eagerley garbage
Expand All @@ -18,6 +19,7 @@ def test_histogram_2D(make_napari_viewer, astronaut_data):
@pytest.mark.mpl_image_compare
def test_histogram_3D(make_napari_viewer, brain_data):
viewer = make_napari_viewer()
viewer.theme = "light"
viewer.add_image(brain_data[0], **brain_data[1])
axis = viewer.dims.last_used
slice_no = brain_data[0].shape[0] - 1
Expand Down
2 changes: 2 additions & 0 deletions src/napari_matplotlib/tests/test_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@pytest.mark.mpl_image_compare
def test_slice_3D(make_napari_viewer, brain_data):
viewer = make_napari_viewer()
viewer.theme = "light"
viewer.add_image(brain_data[0], **brain_data[1])
axis = viewer.dims.last_used
slice_no = brain_data[0].shape[0] - 1
Expand All @@ -21,6 +22,7 @@ def test_slice_3D(make_napari_viewer, brain_data):
@pytest.mark.mpl_image_compare
def test_slice_2D(make_napari_viewer, astronaut_data):
viewer = make_napari_viewer()
viewer.theme = "light"
viewer.add_image(astronaut_data[0], **astronaut_data[1])
fig = SliceWidget(viewer).figure
# Need to return a copy, as original figure is too eagerley garbage
Expand Down
39 changes: 39 additions & 0 deletions src/napari_matplotlib/tests/test_theme.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import napari
import numpy as np
import pytest

from napari_matplotlib import ScatterWidget
from napari_matplotlib.base import NapariMPLWidget


Expand Down Expand Up @@ -49,3 +51,40 @@ def test_theme_background_check(make_napari_viewer):
_mock_up_theme()
viewer.theme = "blue"
assert widget._theme_has_light_bg() is True


@pytest.mark.parametrize(
"theme_name, expected_text_colour",
[
("dark", "#f0f1f2"), # #f0f1f2 is a light grey (almost white)
("light", "#3b3a39"), # #3b3a39 is a brownish dark grey (almost black)
],
)
def test_titles_respect_theme(
make_napari_viewer, theme_name, expected_text_colour
):
"""
Test that the axis labels and titles are the correct color for the napari theme.
"""
viewer = make_napari_viewer()
widget = ScatterWidget(viewer)
viewer.theme = theme_name

# make a scatter plot of two random layers
viewer.add_image(np.random.random((10, 10)), name="first test image")
viewer.add_image(np.random.random((10, 10)), name="second test image")
viewer.layers.selection.clear()
viewer.layers.selection.add(viewer.layers[0])
viewer.layers.selection.add(viewer.layers[1])

ax = widget.figure.gca()

# sanity test to make sure we've got the correct image names
assert ax.xaxis.label.get_text() == "first test image"
assert ax.yaxis.label.get_text() == "second test image"

# print(dir(ax.yaxis.label))
# TODO: put checks of the axis tick labels here

assert ax.xaxis.label.get_color() == expected_text_colour
assert ax.yaxis.label.get_color() == expected_text_colour