From 4c31522714d9b9d0bf288183b6f85d53c99b4dc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= <38459088+jo-mueller@users.noreply.github.com> Date: Mon, 13 Feb 2023 08:16:07 +0100 Subject: [PATCH 1/8] added colorsetting function --- src/napari_matplotlib/base.py | 33 ++++++++++++++++++++++-------- src/napari_matplotlib/histogram.py | 1 + src/napari_matplotlib/scatter.py | 1 + 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/napari_matplotlib/base.py b/src/napari_matplotlib/base.py index b4d8c7cf..6e7c298f 100644 --- a/src/napari_matplotlib/base.py +++ b/src/napari_matplotlib/base.py @@ -13,15 +13,6 @@ 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" @@ -133,6 +124,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 0 + # changing color of axes background to napari main window color + self.canvas.figure.patch.set_facecolor("#262930") + + # changing color of plot background to napari main window color + self.axes.set_facecolor("#262930") + + # changing colors of all axes + self.axes.spines["bottom"].set_color("white") + self.axes.spines["top"].set_color("white") + self.axes.spines["right"].set_color("white") + self.axes.spines["left"].set_color("white") + 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: From 975258fbc99c4700159f315dfa44d2d19813014e Mon Sep 17 00:00:00 2001 From: Johannes Soltwedel <38459088+jo-mueller@users.noreply.github.com> Date: Tue, 2 May 2023 11:22:08 +0200 Subject: [PATCH 2/8] Update src/napari_matplotlib/base.py Co-authored-by: David Stansby --- src/napari_matplotlib/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/napari_matplotlib/base.py b/src/napari_matplotlib/base.py index 6e7c298f..dc0bc5e0 100644 --- a/src/napari_matplotlib/base.py +++ b/src/napari_matplotlib/base.py @@ -129,7 +129,7 @@ def apply_napari_colorscheme(self): Apply napari-compatible colorscheme to the axes object. """ if self.axes is None: - return 0 + return # changing color of axes background to napari main window color self.canvas.figure.patch.set_facecolor("#262930") From 0268e35cb70be285b901d6b3bf70cca16b7f8ed9 Mon Sep 17 00:00:00 2001 From: Johannes Soltwedel <38459088+jo-mueller@users.noreply.github.com> Date: Tue, 2 May 2023 11:22:28 +0200 Subject: [PATCH 3/8] Update src/napari_matplotlib/base.py Co-authored-by: David Stansby --- src/napari_matplotlib/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/napari_matplotlib/base.py b/src/napari_matplotlib/base.py index dc0bc5e0..9af49bd3 100644 --- a/src/napari_matplotlib/base.py +++ b/src/napari_matplotlib/base.py @@ -130,7 +130,7 @@ def apply_napari_colorscheme(self): """ if self.axes is None: return - # changing color of axes background to napari main window color + # changing color of axes background to napari main window color self.canvas.figure.patch.set_facecolor("#262930") # changing color of plot background to napari main window color From 4f691b90d5063abdd02a5957b7729abc069dcb47 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 2 May 2023 09:23:08 +0000 Subject: [PATCH 4/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/napari_matplotlib/base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/napari_matplotlib/base.py b/src/napari_matplotlib/base.py index 9af49bd3..323e669b 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, From b39844126bb3c601118ed5dac7046dbfce65c530 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= <38459088+jo-mueller@users.noreply.github.com> Date: Tue, 2 May 2023 15:45:46 +0200 Subject: [PATCH 5/8] added iteration through spines --- src/napari_matplotlib/base.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/napari_matplotlib/base.py b/src/napari_matplotlib/base.py index 323e669b..cbd56218 100644 --- a/src/napari_matplotlib/base.py +++ b/src/napari_matplotlib/base.py @@ -136,10 +136,7 @@ def apply_napari_colorscheme(self): self.axes.set_facecolor("#262930") # changing colors of all axes - self.axes.spines["bottom"].set_color("white") - self.axes.spines["top"].set_color("white") - self.axes.spines["right"].set_color("white") - self.axes.spines["left"].set_color("white") + [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") From e9f4345ad3e874d8489eb38efc25182f882fde13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= <38459088+jo-mueller@users.noreply.github.com> Date: Tue, 2 May 2023 16:51:49 +0200 Subject: [PATCH 6/8] put napari color in global variable --- src/napari_matplotlib/base.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/napari_matplotlib/base.py b/src/napari_matplotlib/base.py index cbd56218..269c3eda 100644 --- a/src/napari_matplotlib/base.py +++ b/src/napari_matplotlib/base.py @@ -15,6 +15,7 @@ # 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"] @@ -48,7 +49,7 @@ def __init__(self, napari_viewer: napari.viewer.Viewer): self.viewer = napari_viewer self.canvas = FigureCanvas() self.canvas.figure.set_tight_layout(True) - self.canvas.figure.patch.set_facecolor("#262930") + self.canvas.figure.patch.set_facecolor(NAPARI_WINDOW_COLOR) self.toolbar = NapariNavigationToolbar(self.canvas, self) self._replace_toolbar_icons() @@ -130,10 +131,10 @@ def apply_napari_colorscheme(self): if self.axes is None: return # changing color of axes background to napari main window color - self.canvas.figure.patch.set_facecolor("#262930") + self.canvas.figure.patch.set_facecolor(NAPARI_WINDOW_COLOR) # changing color of plot background to napari main window color - self.axes.set_facecolor("#262930") + 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] From 5793fb2348e492bc34a7fad8df780dad0f7a4bb1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 2 May 2023 14:58:08 +0000 Subject: [PATCH 7/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/napari_matplotlib/base.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/napari_matplotlib/base.py b/src/napari_matplotlib/base.py index 7be58d33..f735304a 100644 --- a/src/napari_matplotlib/base.py +++ b/src/napari_matplotlib/base.py @@ -139,7 +139,10 @@ def apply_napari_colorscheme(self): 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.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") From f0bd47b7ae033e2f532ba1349a7365b48a82767c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= <38459088+jo-mueller@users.noreply.github.com> Date: Tue, 2 May 2023 17:12:24 +0200 Subject: [PATCH 8/8] removed deprecated layout engine. --- src/napari_matplotlib/base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/napari_matplotlib/base.py b/src/napari_matplotlib/base.py index f735304a..103e10d8 100644 --- a/src/napari_matplotlib/base.py +++ b/src/napari_matplotlib/base.py @@ -49,7 +49,6 @@ def __init__(self, napari_viewer: napari.viewer.Viewer): self.viewer = napari_viewer self.canvas = FigureCanvas() - self.canvas.figure.set_tight_layout(True) self.canvas.figure.patch.set_facecolor(NAPARI_WINDOW_COLOR) self.canvas.figure.set_layout_engine("constrained") self.toolbar = NapariNavigationToolbar(self.canvas, self)