diff --git a/docs/tutorials/ball-and-stick-1.ipynb b/docs/tutorials/ball-and-stick-1.ipynb index b241137d54..783e469705 100644 --- a/docs/tutorials/ball-and-stick-1.ipynb +++ b/docs/tutorials/ball-and-stick-1.ipynb @@ -1065,13 +1065,9 @@ "metadata": {}, "outputs": [], "source": [ - "import bokeh.plotting as plt\n", - "from bokeh.core.serialization import Serializer\n", "from bokeh.io import output_notebook\n", + "import bokeh.plotting as plt\n", "\n", - "Serializer.register(\n", - " h.Vector, lambda obj, serializer: [serializer.encode(item) for item in obj]\n", - ")\n", "output_notebook()" ] }, diff --git a/docs/tutorials/scripting-neuron-basics.ipynb b/docs/tutorials/scripting-neuron-basics.ipynb index 310f6db287..6bd65e49a3 100644 --- a/docs/tutorials/scripting-neuron-basics.ipynb +++ b/docs/tutorials/scripting-neuron-basics.ipynb @@ -789,26 +789,6 @@ "output_notebook()" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We also need to register a custom serialization function with Bokeh in order to plot Hoc vectors directly:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from bokeh.core.serialization import Serializer\n", - "\n", - "Serializer.register(\n", - " h.Vector, lambda obj, serializer: [serializer.encode(item) for item in obj]\n", - ")" - ] - }, { "cell_type": "markdown", "metadata": {}, diff --git a/share/lib/python/neuron/__init__.py b/share/lib/python/neuron/__init__.py index 36bca6d407..fceb727372 100644 --- a/share/lib/python/neuron/__init__.py +++ b/share/lib/python/neuron/__init__.py @@ -1836,3 +1836,13 @@ def _mview_html_tree(hlist, inside_mechanisms_in_use=0): if _get_ipython() is not None: html_formatter = _get_ipython().display_formatter.formatters["text/html"] html_formatter.for_type(hoc.HocObject, _hocobj_html) + +# in case Bokeh is installed, register a serialization function for hoc.Vector +try: + from bokeh.core.serialization import Serializer + + Serializer.register( + h.Vector, lambda obj, serializer: [serializer.encode(item) for item in obj] + ) +except ImportError: + pass