Javascript Error: IPython is not defined

Continuing the discussion from Setup / Husky – multiple errors in jupyter notebooks, which lists the configuration:

Going through 0 - Introduction to Jupyter Notebooks.ipynb.

The “dynamic plots” using %matplotlib notebook throw the error,
Javascript Error: IPython is not defined.

Changing each instance of %matplotlib notebook to %matplotlib inline works around this (per earlier post). However, the resulting plot does not appear to be interactive.

The linked article said to post again if folks experience this issue, so a proper fix can be provided.

What is the proper fix here?

Hi,

As per that thread, use cw.plot() instead of matplotlib.

1 Like

Ok, that results in an interactive plot in the first instance.


code from cells in question

# was:
# %matplotlib notebook
# import matplotlib.pylab as plt
import chipwhisperer as cw

# was:
# `fig = plt.figure()`
fig = cw.plot()
# fig == Holoviews Curve object
# .../holoviews/element/chart.py

import time
for i in range(0, 10):

    # was:
    # plt.plot(-5, i, '.')
    # fig.canvas.draw()

    # A) this throws an exception
    cw.plot(-5, i, '.')
    
    # B) this also throws an exception
    fig.canvas.draw()
    time.sleep(1)

Exception from (A)

Based on the exception thrown, I attempted to get help on what parameters cw.plot() expects, by using shift-tab per earlier tutorial steps:
args and kwargs are the same as a typical Holoviews plot.

While accurate, this is not helpful for a beginner notebook.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[13], line 5
      1 import time
      2 
      3 for i in range(0, 10):
      4     ## to update the plot:
----> 5     cw.plot(-5, i, '.')
      6     fig.canvas.draw()
      7     time.sleep(1)

File ~/src/chipwhisperer/software/chipwhisperer/__init__.py:556, in plot(*args, **kwargs)
    554 _default_opts = {'height': 600, 'width': 800, 'framewise': True, 'tools': ['hover'], 'active_tools': ['box_zoom']}
    555 hv.extension('bokeh', logo=False) #don't display logo, otherwise it pops up everytime this func is called.
--> 556 return hv.Curve(*args, **kwargs).opts(**_default_opts)

File ~/.cwvenv/lib/python3.12/site-packages/holoviews/element/selection.py:25, in SelectionIndexExpr.__init__(self, *args, **kwargs)
     24 def __init__(self, *args, **kwargs):
---> 25     super().__init__(*args, **kwargs)
     26     self._index_skip = False

File ~/.cwvenv/lib/python3.12/site-packages/holoviews/element/chart.py:51, in Chart.__init__(self, data, kdims, vdims, **params)
     50 def __init__(self, data, kdims=None, vdims=None, **params):
---> 51     params.update(process_dimensions(kdims, vdims))
     52     if len(params.get('kdims', [])) == self._max_kdim_count + 1:
     53         self.param.warning('Chart elements should only be supplied a single kdim')

File ~/.cwvenv/lib/python3.12/site-packages/holoviews/core/dimension.py:119, in process_dimensions(kdims, vdims)
    117         dims = [dims]
    118     elif not isinstance(dims, list):
--> 119         raise ValueError(
    120             f"{group} argument expects a Dimension or list of dimensions, "
    121             "specified as tuples, strings, dictionaries or Dimension "
    122             f"instances, not a {type(dims).__name__} type. "
    123             "Ensure you passed the data as the first argument."
    124         )
    125     dimensions[group] = [asdim(d) for d in dims]
    126 return dimensions

ValueError: kdims argument expects a Dimension or list of dimensions, specified as tuples, strings, dictionaries or Dimension instances, not a int type. Ensure you passed the data as the first argument.

Exception from (B)

No canvas property? That should be easy to track down, right? So I loaded up the code for Curve and started looking for what properties that object would expose:

class Curve(Selection1DExpr, Chart) ...
  class Selection1DExpr(Selection2DExpr) ...
    class Selection2DExpr(SelectionIndexExpr): ...
  class Chart(Dataset, Element2D): ...
    class Dataset(Element, metaclass=PipelineMeta): ...
      class Element(ViewableElement, Composable, Overlayable): ...

I then gave up … I shouldn’t need to be an expert in that particular graph library to go through the introduction to this fine product.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[2], line 6
      2 
      3 for i in range(0, 10):
      4     ## to update the plot:
      5     #cw.plot(-5, i, '.')
----> 6     fig.canvas.draw()
      7     time.sleep(1)

AttributeError: 'Curve' object has no attribute 'canvas'

Recommendation for the update to the loop / canvas code in those next cells?

Perhaps I should rephrase the question:

What is the current method to dynamically add data elements to the dataplot, when using cw.plot() instead of the legacy method that relied directly on %matplotlib notebook?