Skip to content

Commit 017a572

Browse files
committed
renormalize the plots value axis on every update
1 parent e920210 commit 017a572

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

adaptive/learner/balancing_learner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def plot_function(*args):
279279
dm = dm.redim.values(**d)
280280

281281
if dynamic:
282-
return dm
282+
return dm.map(lambda obj: obj.opts(framewise=True), hv.Element)
283283
else:
284284
# XXX: change when https://github.com/ioam/holoviews/issues/3085
285285
# is fixed.

adaptive/notebook_integration.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ def in_ipynb():
8484
active_plotting_tasks = dict()
8585

8686

87-
def live_plot(runner, *, plotter=None, update_interval=2, name=None):
87+
def live_plot(runner, *, plotter=None, update_interval=2,
88+
name=None, normalize=True):
8889
"""Live plotting of the learner's data.
8990
9091
Parameters
@@ -99,15 +100,19 @@ def live_plot(runner, *, plotter=None, update_interval=2, name=None):
99100
Name for the `live_plot` task in `adaptive.active_plotting_tasks`.
100101
By default the name is None and if another task with the same name
101102
already exists that other `live_plot` is canceled.
103+
normalize : bool
104+
Normalize (scale to fit) the frame upon each update.
102105
103106
Returns
104107
-------
105108
dm : `holoviews.core.DynamicMap`
106109
The plot that automatically updates every `update_interval`.
107110
"""
108111
if not _holoviews_enabled:
109-
raise RuntimeError("Live plotting is not enabled; did you run "
110-
"'adaptive.notebook_extension()'?")
112+
raise RuntimeError(
113+
"Live plotting is not enabled; did you run "
114+
"'adaptive.notebook_extension()'?"
115+
)
111116

112117
import holoviews as hv
113118
import ipywidgets
@@ -123,8 +128,12 @@ def plot_generator():
123128
else:
124129
yield plotter(runner.learner)
125130

126-
dm = hv.DynamicMap(plot_generator(),
127-
streams=[hv.streams.Stream.define('Next')()])
131+
steams = [hv.streams.Stream.define("Next")()]
132+
dm = hv.DynamicMap(plot_generator(), streams=streams)
133+
134+
if normalize:
135+
dm = dm.map(lambda obj: obj.opts(framewise=True), hv.Element)
136+
128137
cancel_button = ipywidgets.Button(description='cancel live-plot',
129138
layout=ipywidgets.Layout(width='150px'))
130139

0 commit comments

Comments
 (0)