Skip to content

Commit

Permalink
Feature/vertical plots (#26)
Browse files Browse the repository at this point in the history
* Moves interactive plots into earthkit.plots.interactive

* Adds plotly to requirements

* Moves interactive plots into earthkit.plots.interactive

* Remove empty notebook

* QA tweaks

* Adds default style to improve look and feel with >5 quantiles

* Adds default style to improve look and feel with >5 quantiles

* Adds docstrings

* Adds tests for interactive plots

* QA tweaks

* Adds better support for interactive vertical plots
  • Loading branch information
JamesVarndell authored Nov 17, 2024
1 parent c4f485a commit 7b30200
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions src/earthkit/plots/interactive/charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def __init__(self, rows=None, columns=None, **kwargs):
self._subplots_kwargs = kwargs
self._subplot_titles = None
self._subplot_y_titles = None
self._subplot_x_titles = None
self._layout_override = dict()

def set_subplot_titles(method):
Expand All @@ -84,10 +85,14 @@ def wrapper(self, *args, **kwargs):
pass
else:
self._subplot_titles = list(ds.data_vars)
self._subplot_y_titles = [
titles = [
ds[data_var].attrs.get("units", "")
for data_var in ds.data_vars
]
if kwargs.get("y") is not None:
self._subplot_x_titles = titles
else:
self._subplot_y_titles = titles
return method(self, *args, **kwargs)

return wrapper
Expand Down Expand Up @@ -286,13 +291,24 @@ def show(self, *args, **kwargs):
for i in range(self.rows * self.columns):
y_key = f"yaxis{i+1 if i>0 else ''}"
x_key = f"xaxis{i+1 if i>0 else ''}"
self.fig.update_layout(
**{
x_key: layout["xaxis"],
y_key: {
**layout["yaxis"],
**{"title": self._subplot_y_titles[i]},
},
}
)
if self._subplot_x_titles:
self.fig.update_layout(
**{
y_key: layout["yaxis"],
x_key: {
**layout["xaxis"],
**{"title": self._subplot_x_titles[i]},
},
}
)
if self._subplot_y_titles:
self.fig.update_layout(
**{
x_key: layout["xaxis"],
y_key: {
**layout["yaxis"],
**{"title": self._subplot_y_titles[i]},
},
}
)
return self.fig.show(*args, **kwargs)

0 comments on commit 7b30200

Please sign in to comment.