Open DIYer22 opened 6 years ago
Since you're using the Jupyter notebook to render graphs, you would need to explicitly make IPython work with matplotlib to render graphs within your cells.
You can do so by using this command before you plot:
%matplotlib inline
And you only need to do this once.
Try running the following code for your first cell:
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot([0, 1, 2, 5])
plt.show()
@adharsh Thanks, but I still think that if first cell can't render, the second cell shouldn't render too.
Does the first render work in an older version of the notebook?
Also, could you try an older version of matplotlib to see whether the problem arises there?
@mpacer I try it on Python 2.7 and notebook server is 5.0.0, first render work well.
I'm seeing the exact same behavior, whenever I launch a notebook, the very first plot I try to render is not displayed. All subsequent plots are displayed. I have to rerun the first cell for the plot to be displayed.
I'm experiencing the same issue. The first plot in new notebook (or after kernel restart) is not shown:
However I found two work-arounds:
%matplotlib inline
in the cell where you first import the matplotlib
matplotlib
in previous cell:
Version information:
Same issue.
Notebook server 5.7.0, Python 3.6.6, IPython 7.0.1, matplotlib 3.0.2.
Same issue python 3.7.1 notebook 5.7.4 ipython 7.2.0
Same issue python 3.6.8 notebook 5.7.4 ipython 7.2.0
Same issue Python 3.7.6 notebook 5.7.8 ipython 7.2.0
Same issue Python 3.8.2 jupyter-notebook : 6.0.3 ipython : 7.13.0
@atomicwelding - could you please reconfirm with IPython 7.13.0? The IPython version matters for the kernel's runtime environment, not the notebook (in case you're spanning envs).
I have confirmed this works on both 7.10 and 7.13 and confirmed it didn't work on 7.8.0. I just found that @benjimin fixed this via https://github.com/ipython/ipython/pull/11916 - which first appears in 7.10.
EDIT: Since there may be a relation with ipykernel, my ipykernel version is 5.2.1 (but that remained constant over both success and failure trials).
Still doesn't work for me:
I've tried %matplotlib inline, %matplotlib notebook, and changed backend to TkAgg ( ref )
My code looks something like this:
<%matplotlib inline>
<import matplotlib>
<matplotlib.use('TkAgg')>
<import matplotlib.pyplot as plt>
and finally <plt.show()>
No result on running the cell - not even an address. Code works fine, an associated file is being updated and returned successfully.
Python 3.8.5 Jupyter 6.1.4 IPython 7.19.0
If plot something in first cell after
import matplotlib.pyplot as plt
notebook won't render the figure.
But run second cell is rendered.