The plots are not displayed inline in notebooks when using matplotlib
The plots appear completely blank. Any ideas?
Came across the same issue on calling "Restart & Run all". Following this
%matplotlib notebook showing a blank histogram
I could resolve the issue adding
%matplotlib inline at the beginning of the cell. Also note that you can prevent string output by adding ; to the end of a line.
I faced a similar issue with my Chrome Browser, whereas it works fine with Mozilla.
%matplotlib inline will lead to static images of your plot embedded in the notebook, so that cannot be the solution for this prevailing issue.
I find inconsistent behaviour, but any of the following 2 methods should work:
Method 1 Start a cell like so:
import matplotlib matplotlib.use('TkAgg') from matplotlib import pyplot as plt plt.ion() Then in the next cell type:
plt.hist([3,8,10]) In most cases the plot will appear in its own window.
Method 2 However, sometimes (not sure why), this does not work even after a kernel restart.
You may see a little window appear that does not show the plot but remains blank and if you hover over it with the mouse, you'll get the "thinking" icon.
In that case end your plotting cell like so:
plt.pause(1) This should show the plots in the figures and they should be responsive too.
Good luck!
Tested on:
Windows 10 jupyter running inside Visual Studio Code 1.83.1 jupyter_client==8.6.0 jupyter_core==5.7.1 jupyterlab_widgets==3.0.10 python 3.10.13 matplotlib 3.8.2 I got solution on this. Object creation, add_axes and plot do in one cell you will get result.
%matplotlib notebook. In my case I had to import them too.matplotlib.pyplot.show()works.