Skip to content

Commit 2208d1a

Browse files
committed
add an option to plot a HoloMap with the BalancingLearner
This can be used with the live_plot functionality and HoloMaps are exportable to html.
1 parent 497c576 commit 2208d1a

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

adaptive/learner/balancing_learner.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def loss(self, real=True):
146146
losses = self.losses(real)
147147
return max(losses)
148148

149-
def plot(self, cdims=None, plotter=None):
149+
def plot(self, cdims=None, plotter=None, dynamic=True):
150150
"""Returns a DynamicMap with sliders.
151151
152152
Parameters
@@ -166,10 +166,16 @@ def plot(self, cdims=None, plotter=None):
166166
plotter : callable, optional
167167
A function that takes the learner as a argument and returns a
168168
holoviews object. By default learner.plot() will be called.
169+
dynamic : bool, default True
170+
Return a holoviews.DynamicMap if True, else a holoviews.HoloMap.
171+
The DynamicMap is rendered as the sliders change and can therefore
172+
not be exported to html. The HoloMap does not have this problem.
173+
169174
Returns
170175
-------
171-
dm : holoviews.DynamicMap object
172-
A DynamicMap with sliders that are defined by 'cdims'.
176+
dm : holoviews.DynamicMap object (default) or holoviews.HoloMap object
177+
A DynamicMap (dynamic=True) or HoloMap (dynamic=False) with
178+
sliders that are defined by 'cdims'.
173179
"""
174180
hv = ensure_holoviews()
175181
cdims = cdims or self._cdims_default
@@ -194,7 +200,15 @@ def plot_function(*args):
194200
return learner.plot() if plotter is None else plotter(learner)
195201

196202
dm = hv.DynamicMap(plot_function, kdims=list(d.keys()))
197-
return dm.redim.values(**d)
203+
dm = dm.redim.values(**d)
204+
205+
if dynamic:
206+
return dm
207+
else:
208+
# XXX: change when https://github.com/ioam/holoviews/issues/3085
209+
# is fixed.
210+
vals = {d.name: d.values for d in dm.dimensions() if d.values}
211+
return hv.HoloMap(dm.select(**vals))
198212

199213
def remove_unfinished(self):
200214
"""Remove uncomputed data from the learners."""

0 commit comments

Comments
 (0)