Skip to content
Snippets Groups Projects

Resolve "(LearnerND) add iso-surface plot feature"

Merged Jorn Hoofwijk requested to merge 112-learnernd-add-iso-surface-plot-feature into master
All threads resolved!
Compare and Show latest version
1 file
+ 29
26
Compare changes
  • Side-by-side
  • Inline
@@ -7,34 +7,37 @@ import warnings
_async_enabled = False
_plotting_enabled = False
_plotly_notebook_imported = False
_holoviews_enabled = False
_ipywidgets_enabled = False
_plotly_enabled = False
def notebook_extension():
if not in_ipynb():
raise RuntimeError('"adaptive.notebook_extension()" may only be run '
'from a Jupyter notebook.')
global _plotting_enabled
_plotting_enabled = False
global _async_enabled, _holoviews_enabled, _ipywidgets_enabled
try:
import ipywidgets
import holoviews
holoviews.notebook_extension('bokeh')
_plotting_enabled = True
if not _holoviews_enabled:
import holoviews
holoviews.notebook_extension('bokeh')
_holoviews_enabled = True
except ModuleNotFoundError:
warnings.warn("holoviews and (or) ipywidgets are not installed; plotting "
warnings.warn("holoviews are not installed; plotting "
"is disabled.", RuntimeWarning)
try:
import plotly.offline
plotly.offline.init_notebook_mode()
if not _ipywidgets_enabled:
import ipywidgets
_ipywidgets_enabled = True
except ModuleNotFoundError:
pass
warnings.warn("ipywidgets are not installed; plotting "
"is disabled.", RuntimeWarning)
global _async_enabled
get_ipython().magic('gui asyncio')
_async_enabled = True
if not _async_enabled:
get_ipython().magic('gui asyncio')
_async_enabled = True
def ensure_holoviews():
@@ -50,21 +53,21 @@ def ensure_plotly():
"plotting functions using 'plotly' may only be run "
"from a Jupyter notebook.")
global _plotly_notebook_imported
global _plotly_enabled
try:
import plotly.graph_objs
import plotly.figure_factory
import plotly.offline
plotly = importlib.import_module('plotly')
if not _plotly_notebook_imported:
import plotly
if not _plotly_enabled:
import plotly.graph_objs
import plotly.figure_factory
import plotly.offline
# This injects javascript and should happen only once
plotly.offline.init_notebook_mode()
_plotly_notebook_imported = True
_plotly_enabled = True
return plotly
except ModuleNotFoundError:
raise RuntimeError('plotly is not installed; plotting is disabled.')
def in_ipynb():
try:
# If we are running in IPython, then `get_ipython()` is always a global
@@ -99,7 +102,7 @@ def live_plot(runner, *, plotter=None, update_interval=2, name=None):
dm : holoviews.DynamicMap
The plot that automatically updates every update_interval.
"""
if not _plotting_enabled:
if not _holoviews_enabled:
raise RuntimeError("Live plotting is not enabled; did you run "
"'adaptive.notebook_extension()'?")
@@ -153,7 +156,7 @@ def live_info(runner, *, update_interval=0.5):
Returns an interactive ipywidget that can be
visualized in a Jupyter notebook.
"""
if not _plotting_enabled:
if not _holoviews_enabled:
raise RuntimeError("Live plotting is not enabled; did you run "
"'adaptive.notebook_extension()'?")
Loading