Skip to content

Commit 4c31522

Browse files
committed
added colorsetting function
1 parent 308134b commit 4c31522

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

Diff for: src/napari_matplotlib/base.py

+24-9
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@
1313

1414
from .util import Interval
1515

16-
mpl.rc("axes", edgecolor="white")
17-
mpl.rc("axes", facecolor="#262930")
18-
mpl.rc("axes", labelcolor="white")
19-
mpl.rc("savefig", facecolor="#262930")
20-
mpl.rc("text", color="white")
21-
22-
mpl.rc("xtick", color="white")
23-
mpl.rc("ytick", color="white")
24-
2516
# Icons modified from
2617
# https://github.com/matplotlib/matplotlib/tree/main/lib/matplotlib/mpl-data/images
2718
ICON_ROOT = Path(__file__).parent / "icons"
@@ -133,6 +124,30 @@ def draw(self) -> None:
133124
This is a no-op, and is intended for derived classes to override.
134125
"""
135126

127+
def apply_napari_colorscheme(self):
128+
"""
129+
Apply napari-compatible colorscheme to the axes object.
130+
"""
131+
if self.axes is None:
132+
return 0
133+
# changing color of axes background to napari main window color
134+
self.canvas.figure.patch.set_facecolor("#262930")
135+
136+
# changing color of plot background to napari main window color
137+
self.axes.set_facecolor("#262930")
138+
139+
# changing colors of all axes
140+
self.axes.spines["bottom"].set_color("white")
141+
self.axes.spines["top"].set_color("white")
142+
self.axes.spines["right"].set_color("white")
143+
self.axes.spines["left"].set_color("white")
144+
self.axes.xaxis.label.set_color("white")
145+
self.axes.yaxis.label.set_color("white")
146+
147+
# changing colors of axes labels
148+
self.axes.tick_params(axis="x", colors="white")
149+
self.axes.tick_params(axis="y", colors="white")
150+
136151
def _on_update_layers(self) -> None:
137152
"""
138153
This function is called when self.layers is updated via

Diff for: src/napari_matplotlib/histogram.py

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class HistogramWidget(NapariMPLWidget):
2222
def __init__(self, napari_viewer: napari.viewer.Viewer):
2323
super().__init__(napari_viewer)
2424
self.axes = self.canvas.figure.subplots()
25+
self.apply_napari_colorscheme()
2526
self.update_layers(None)
2627

2728
def clear(self) -> None:

Diff for: src/napari_matplotlib/scatter.py

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def __init__(self, napari_viewer: napari.viewer.Viewer):
2828
super().__init__(napari_viewer)
2929

3030
self.axes = self.canvas.figure.subplots()
31+
self.apply_napari_colorscheme()
3132
self.update_layers(None)
3233

3334
def clear(self) -> None:

0 commit comments

Comments
 (0)