# Error displaying animation

**URL:** <https://discourse.jupyter.org/t/error-displaying-animation/28149>\
**Category:** JupyterLab\
**Created:** [September 5, 2024, 8:07pm UTC](https://discourse.jupyter.org/t/error-displaying-animation/28149 "2024-09-05T20:07:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex1](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/alex1/32/14689_2.png) [@Alex1](https://discourse.jupyter.org/u/Alex1)\
**Post date:** [September 5, 2024, 8:07pm UTC](https://discourse.jupyter.org/t/error-displaying-animation/28149/1 "2024-09-05T20:07:53Z")

</div>

Right now I can run, for example, the following code:

```auto
import numpy as np
import math
import hypertools as hyp
%matplotlib inline
arr = np.array( [[math.sin(3*i/100), math.cos (3*i/100), (1/100)**2, (i/100)**3, 1/(1+i/100)] for i in range(0,300)])
hyp.plot(arr)

```

That works. I’d like to do

```auto
hyp.plot(arr, animate=True)

```

but that returns an error:  
`Javascript Error: IPython is not defined`

Can anyone tell me how to get this to work? I’m using jupyterlab 4.2.3

---

<div class="post-metadata">

**Author:** ![fomightez](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/fomightez/32/495_2.png) [@fomightez](https://discourse.jupyter.org/u/fomightez)\
**Post date:** [September 5, 2024, 8:26pm UTC](https://discourse.jupyter.org/t/error-displaying-animation/28149/2 "2024-09-05T20:26:59Z")

</div>

This is incomplete code or the formatting got messed up because you didn’t [use fenced code blocks to share code](https://docs.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#fenced-code-blocks). (I get `SyntaxError: invalid decimal literal` concerning the `3i` in `arr = np.array( [[math.sin(3i/100), math.cos (3i/100), (1/100)**2, (i/100)**3, 1/(1+i/100)] for i in range(0,300)])`.) And so I cannot actually test before suggesting things.

I suspect though you are looking to **install and use `ipympl`**. See [here](https://discourse.jupyter.org/t/matplotlib-animation-not-appearing-in-jupyter-notebook/24938/5) above the ’ Optional version with a player controller …’ section. You’ll need to transpose it to your code. It should mainly mean changing things to add `%matplotlib ipympl` at the start of the cell with the animation.

---

<div class="post-metadata">

**Author:** ![Alex1](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/alex1/32/14689_2.png) [@Alex1](https://discourse.jupyter.org/u/Alex1)\
**Post date:** [September 5, 2024, 8:33pm UTC](https://discourse.jupyter.org/t/error-displaying-animation/28149/3 "2024-09-05T20:33:24Z")

</div>

Sorry, here it is again properly (and I edited the original post to fix it)

```auto
import numpy as np
import math
import hypertools as hyp
%matplotlib inline
arr = np.array( [[math.sin(3*i/100), math.cos (3*i/100), (1/100)**2, (i/100)**3, 1/(1+i/100)] for i in range(0,300)])
hyp.plot(arr)

```

I tried using `%matplotlib ipympl` but I get the same error

---

<div class="post-metadata">

**Author:** ![fomightez](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/fomightez/32/495_2.png) [@fomightez](https://discourse.jupyter.org/u/fomightez)\
**Post date:** [September 5, 2024, 8:47pm UTC](https://discourse.jupyter.org/t/error-displaying-animation/28149/4 "2024-09-05T20:47:32Z")

</div>

It was supposedly fixed in response to [this issue report here](https://github.com/ContextLab/hypertools/issues/261#issue-2180427238).  
And I know how to get it working for now in fresh sessions via MyBinder:  
The additional trick **NOW** , beyond what is stated [here](https://github.com/ContextLab/hypertools/issues/261#issue-2180427238), is you need to specify numpy\>=1.10.4 **but not 2.0 or above**. If you use numpy 2.0 or above, you get `AttributeError: `np.string\_`was removed in the NumPy 2.0 release. Use`np.bytes\_` instead.`.  
I found `v1.26.4` is just fine and here is how you can test using hypertools animation via sessions on MyBinder right now:

1. Go [here](https://gist.github.com/fomightez/6773dedf6d5132795dd4245a18c066eb) and click on `launch binder` to get a session with ipympl already installed.

2. When the session comes up, open a new terminal window using the launcher & run in the terminal the following:

3. Next in that terminal run the following, based on [the advice given here](https://github.com/ContextLab/hypertools/issues/261#issue-2180427238):

4. Now using the launcher open a new Jupyter Notebook and in the first cell paste this code and run it:

Alternatively, you can go [here](https://gist.github.com/jtpio/f3f7aed7c87bb15e07009bb29a601ed8) and use Jeremy Tuloup’s (jtpio) related gist to launch a MyBinder session that doesn’t include `ipympl` already installed. (As of September 2024 it also has older Python; currently 3.10.14, but it works fine with this process.) Then follow the steps above, until you get to through step #3. You’ll just need to do a hard refresh in the browser window after the step `pip install git+https://github.com/ContextLab/hypertools.git`, which includes installing `ipympl`, and before launching a new notebook. That refresh step in Chrome on a Mac is `Command + Shift R`. I think on Windows it is `Shift + F5`. Then after the refresh, you can finish the steps above in that session.
