diff --git a/src/napari_matplotlib/base.py b/src/napari_matplotlib/base.py index c580361d..103e10d8 100644 --- a/src/napari_matplotlib/base.py +++ b/src/napari_matplotlib/base.py @@ -2,7 +2,6 @@ from pathlib import Path from typing import List, Tuple -import matplotlib as mpl import napari from matplotlib.backends.backend_qt5agg import ( FigureCanvas, @@ -13,18 +12,10 @@ from .util import Interval -mpl.rc("axes", edgecolor="white") -mpl.rc("axes", facecolor="#262930") -mpl.rc("axes", labelcolor="white") -mpl.rc("savefig", facecolor="#262930") -mpl.rc("text", color="white") - -mpl.rc("xtick", color="white") -mpl.rc("ytick", color="white") - # Icons modified from # https://github.com/matplotlib/matplotlib/tree/main/lib/matplotlib/mpl-data/images ICON_ROOT = Path(__file__).parent / "icons" +NAPARI_WINDOW_COLOR = "#262930" __all__ = ["NapariMPLWidget"] @@ -57,8 +48,9 @@ def __init__(self, napari_viewer: napari.viewer.Viewer): self.viewer = napari_viewer self.canvas = FigureCanvas() + + self.canvas.figure.patch.set_facecolor(NAPARI_WINDOW_COLOR) self.canvas.figure.set_layout_engine("constrained") - self.canvas.figure.patch.set_facecolor("#262930") self.toolbar = NapariNavigationToolbar(self.canvas, self) self._replace_toolbar_icons() @@ -133,6 +125,30 @@ def draw(self) -> None: This is a no-op, and is intended for derived classes to override. """ + def apply_napari_colorscheme(self): + """ + Apply napari-compatible colorscheme to the axes object. + """ + if self.axes is None: + return + # changing color of axes background to napari main window color + self.canvas.figure.patch.set_facecolor(NAPARI_WINDOW_COLOR) + + # changing color of plot background to napari main window color + self.axes.set_facecolor(NAPARI_WINDOW_COLOR) + + # changing colors of all axes + [ + self.axes.spines[spine].set_color("white") + for spine in self.axes.spines + ] + self.axes.xaxis.label.set_color("white") + self.axes.yaxis.label.set_color("white") + + # changing colors of axes labels + self.axes.tick_params(axis="x", colors="white") + self.axes.tick_params(axis="y", colors="white") + def _on_update_layers(self) -> None: """ This function is called when self.layers is updated via diff --git a/src/napari_matplotlib/histogram.py b/src/napari_matplotlib/histogram.py index 1f479ad7..fc99faaf 100644 --- a/src/napari_matplotlib/histogram.py +++ b/src/napari_matplotlib/histogram.py @@ -22,6 +22,7 @@ class HistogramWidget(NapariMPLWidget): def __init__(self, napari_viewer: napari.viewer.Viewer): super().__init__(napari_viewer) self.axes = self.canvas.figure.subplots() + self.apply_napari_colorscheme() self.update_layers(None) def clear(self) -> None: diff --git a/src/napari_matplotlib/scatter.py b/src/napari_matplotlib/scatter.py index 3b0f918c..05b981cb 100644 --- a/src/napari_matplotlib/scatter.py +++ b/src/napari_matplotlib/scatter.py @@ -28,6 +28,7 @@ def __init__(self, napari_viewer: napari.viewer.Viewer): super().__init__(napari_viewer) self.axes = self.canvas.figure.subplots() + self.apply_napari_colorscheme() self.update_layers(None) def clear(self) -> None: