Skip to content

added colorsetting function #65

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 9 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
added colorsetting function
  • Loading branch information
jo-mueller committed Feb 13, 2023
commit 4c31522714d9b9d0bf288183b6f85d53c99b4dc7
33 changes: 24 additions & 9 deletions src/napari_matplotlib/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/napari_matplotlib/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/napari_matplotlib/scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down