From 08a443ca4758b41782f8cbc3e839e8580d521bb7 Mon Sep 17 00:00:00 2001 From: Mike Bender Date: Thu, 20 Jan 2022 18:14:53 -0500 Subject: [PATCH] Add a deephaven.mplstyle file (#4) --- README.md | 3 ++- setup.cfg | 4 ++++ src/deephaven/plugin/matplotlib/__init__.py | 14 +++++++++++++- src/deephaven/plugin/matplotlib/deephaven.mplstyle | 10 ++++++++++ src/deephaven/plugin/matplotlib/figure_type.py | 2 +- 5 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/deephaven/plugin/matplotlib/deephaven.mplstyle diff --git a/README.md b/README.md index ad0d6e6..645069c 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,8 @@ To create your build / development environment: ```sh python3 -m venv .venv source .venv/bin/activate -pip install --upgrade pip setuptools build deephaven-plugin matplotlib +pip install --upgrade pip setuptools +pip install build deephaven-plugin matplotlib ``` To build: diff --git a/setup.cfg b/setup.cfg index d212da3..57cbae6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -27,10 +27,14 @@ packages=find_namespace: install_requires = deephaven-plugin matplotlib +include_package_data = True [options.packages.find] where=src +[options.package_data] +* = *.mplstyle + [options.entry_points] deephaven.plugin = registration_cls = deephaven.plugin.matplotlib:MatplotlibRegistration diff --git a/src/deephaven/plugin/matplotlib/__init__.py b/src/deephaven/plugin/matplotlib/__init__.py index 6fad3ca..c3171e6 100644 --- a/src/deephaven/plugin/matplotlib/__init__.py +++ b/src/deephaven/plugin/matplotlib/__init__.py @@ -1,9 +1,21 @@ from deephaven.plugin import Registration +from importlib import resources +import matplotlib.pyplot as plt -__version__ = "0.0.1.dev5" +__version__ = "0.0.1.dev6" + +def init_theme(): + # Set the Deephaven style globally. + # We use the savefig function to export the Figure, and that uses the Figure's properties for colours rather than temporary styling. + # The Figure's properties are set on creation time of the Figure, rather than when the Figure is exported + # We do not have hooks into when a user creates a new Figure, so we set the theme globally ahead of time + # https://github.com/matplotlib/matplotlib/issues/6592/ + with resources.path(__package__, 'deephaven.mplstyle') as p: + plt.style.use(['dark_background',p]) class MatplotlibRegistration(Registration): @classmethod def register_into(cls, callback: Registration.Callback) -> None: + init_theme() from . import figure_type callback.register(figure_type.FigureType) diff --git a/src/deephaven/plugin/matplotlib/deephaven.mplstyle b/src/deephaven/plugin/matplotlib/deephaven.mplstyle new file mode 100644 index 0000000..3ae2471 --- /dev/null +++ b/src/deephaven/plugin/matplotlib/deephaven.mplstyle @@ -0,0 +1,10 @@ +axes.prop_cycle: cycler('color', ['76d9e4', '9edc6f', 'fcd65b', 'aa9af4', 'f37e3f', 'f95d84', 'f0f0ee']) +axes.facecolor: 2d2a2e +axes.edgecolor: f0f0ee +axes.labelcolor: f0f0ee +xtick.color: f0f0ee +ytick.color: f0f0ee +grid.color: f0f0ee +savefig.facecolor: 2d2a2e +text.color: f0f0ee +lines.color: f0f0ee \ No newline at end of file diff --git a/src/deephaven/plugin/matplotlib/figure_type.py b/src/deephaven/plugin/matplotlib/figure_type.py index 4a3a826..d8e4b64 100644 --- a/src/deephaven/plugin/matplotlib/figure_type.py +++ b/src/deephaven/plugin/matplotlib/figure_type.py @@ -14,5 +14,5 @@ def is_type(self, object) -> bool: def to_bytes(self, exporter: Exporter, figure: Figure) -> bytes: buf = BytesIO() - figure.savefig(buf, format='PNG') + figure.savefig(buf, format='PNG', dpi=144) return buf.getvalue()