Skip to content

Commit

Permalink
renormalize the plots value axis on every update
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt committed Apr 23, 2019
1 parent 4889ab5 commit 5fa2dd4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion adaptive/learner/balancing_learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def plot_function(*args):
dm = dm.redim.values(**d)

if dynamic:
return dm
return dm.map(lambda obj: obj.opts(framewise=True), hv.Element)
else:
# XXX: change when https://github.com/ioam/holoviews/issues/3085
# is fixed.
Expand Down
19 changes: 14 additions & 5 deletions adaptive/notebook_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def in_ipynb():
active_plotting_tasks = dict()


def live_plot(runner, *, plotter=None, update_interval=2, name=None):
def live_plot(runner, *, plotter=None, update_interval=2,
name=None, normalize=True):
"""Live plotting of the learner's data.
Parameters
Expand All @@ -99,15 +100,19 @@ def live_plot(runner, *, plotter=None, update_interval=2, name=None):
Name for the `live_plot` task in `adaptive.active_plotting_tasks`.
By default the name is None and if another task with the same name
already exists that other `live_plot` is canceled.
normalize : bool
Normalize (scale to fit) the frame upon each update.
Returns
-------
dm : `holoviews.core.DynamicMap`
The plot that automatically updates every `update_interval`.
"""
if not _holoviews_enabled:
raise RuntimeError("Live plotting is not enabled; did you run "
"'adaptive.notebook_extension()'?")
raise RuntimeError(
"Live plotting is not enabled; did you run "
"'adaptive.notebook_extension()'?"
)

import holoviews as hv
import ipywidgets
Expand All @@ -123,8 +128,12 @@ def plot_generator():
else:
yield plotter(runner.learner)

dm = hv.DynamicMap(plot_generator(),
streams=[hv.streams.Stream.define('Next')()])
steams = [hv.streams.Stream.define("Next")()]
dm = hv.DynamicMap(plot_generator(), streams=streams)

if normalize:
dm = dm.map(lambda obj: obj.opts(framewise=True), hv.Element)

cancel_button = ipywidgets.Button(description='cancel live-plot',
layout=ipywidgets.Layout(width='150px'))

Expand Down

0 comments on commit 5fa2dd4

Please sign in to comment.