Skip to content

Commit

Permalink
Add a deephaven.mplstyle file (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
mofojed authored Jan 20, 2022
1 parent 461632d commit 08a443c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 13 additions & 1 deletion src/deephaven/plugin/matplotlib/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 10 additions & 0 deletions src/deephaven/plugin/matplotlib/deephaven.mplstyle
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/deephaven/plugin/matplotlib/figure_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 08a443c

Please sign in to comment.