The fix is straightforward, I think, if you are actually using the current version of Jupyter Notebook, which is 7+:
You likely need an installation here and to specify the correct backend for matplotlib to use, see here.
Install ipympl
first, following here. If you are using Anaconda/conda, install with that. You can use %conda install -c conda-forge ipympl
in a new cell in your notebook. Otherwise use pip
. You can also use that in your notebook with %pip install ipympl
.
Let it run completely to finish the install with whatever method you use. Importantly, that won’t fix everything yet because this installation is complex and you need to restart everything to propagate the changes to a new session. So shut down, Jupyter, your browser, and even your entire system and start everything back up.
Next start things back up. In the new Jupyter session with your notebook open, do the following before running your sympy plotting code:
Get rid of the matplotlib notebook
cell entirely. (That was not explicit and the one that is causing an issue as it is not compatible with current Jupyter Notebook 7+ or JupyterLab.)
Replace that cell with a cell that says:
%matplotlib ipympl
That is based on here. (Note I am using the doubly- explicit %matplotlib ipympl
command that specifies clearly it is magic command and matches with what you need to install for using the interactive features of matplotlib, which sympy.plotting
uses; explicit is always better than not in Python.)
Now run your code and the plot should work and you should no longer see Javascript Error: IPython is not defined.
As for this part below:
“I am currently viewing a python instructional videos series offered by my college and completing the respective “assignments” on jupyternotebook in preparation for the coming school year. However, I have suddenly encountered the issue depicted above.”
Do you know how long ago these videos were made? Jupyter Notebook 7+ came out exactly a year ago this week (see the resources referenced in the middle of here for more about that, particularly Announcing Jupyter Notebook 7.
If they pre-date that, then they are likely not matching with current usage of Jupyter Noteboook 7+ since you say you are using the most current version of Jupyter Notebook 7+.
This is not consistent with much of what you’ve said prior. Either you were using current Jupyter Notebook 7+ and the code you show wouldn’t have worked. Or something got updated and now you are using the current Jupyter Notebook 7+.
In the future, always include code as code text in fenced block. Help those trying to help you. (More about this just below the code block.) For the record here is the code aside from the %matplotlib ipympl
that would be placed in a cell at the top of the notebook:
from sympy import *
x=symbols('x')
f =(sqrt(x)*1)/(x**-1)
xval=[0.9, 0.99,0.999, 0.9999, 1.1, 1.01, 1.001, 1.0001]
yval=[f.subs(x,I) for i in xval]
plot(f,(x,0,5));
Please read Getting good answers to your questions. Pay particular attention to ’ DO NOT post images of code, data, error messages, etc’, under the section ‘Help others reproduce the problem’, in the link to How do I ask a good question? at the bottom there. In your case, because you are describing something along the lines of a behavior, a screenshot is justified as part of what is included. See here under ’ Block code formatting’ on how you would paste the code in to have it show with syntax and formatting on Discourse.