Skip to content

Commit

Permalink
Adds better support for interactive vertical plots
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesVarndell committed Nov 17, 2024
1 parent e3e2acf commit db38426
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 db38426

Please sign in to comment.