Issue
Very new to this. I'm in Jupyter Notebook, following instructions to make interactive visualizations. I'm using the following code, taken directly from the site:
from IPython.html.widgets import *
t = arange(0.0, 1.0, 0.01)
def pltsin(f):
plt.plot(x,sin(2*pi*t*f))
plt.show()
interact(pltsin, f=(1,10,0.1))
When I try this, I get the following error:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Input In [3], in <cell line: 10>()
6 print(text.value)
8 text.on_submit(handle_submit)
---> 10 from IPython.html.widgets import *
11 t = arange(0.0, 1.0, 0.01)
13 def pltsin(f):
ModuleNotFoundError: No module named 'IPython.html'
What's the problem here? Is there something I've failed to install? Thanks in advance for the assistance.
Solution
This is a companion to my comment under the OP so that I can add code.
Here is an updated version of the code you have that will work. It is largely based on here which notes that now the ipywidgets documentation features interactive
and not interact
with the matplotlib example. (I was unsure about the x
in the Domino Labs code you linked and so you may want to look at what I did in regards to that.)
from ipywidgets import interactive
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0.0, 1.0, 0.01)
def pltsin(f):
plt.plot(t,np.sin(2*np.pi*t*f))
plt.show()
interactive_plot = interactive(pltsin, f=(1,10,0.1))
interactive_plot
Try it out in your browser without installing anything.
To try it out in a session backed by MyBinder where the environment already has ipywidgets and numpy installed, click here and then choose Run
> Run All Cells
from the main menu to run the code and see the interactive plot.
Answered By - Wayne
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.