I am facing an error which I do not know how to fix. I'm trying to get this piece of code to work on windows but I have this error appearing
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.plot()
Error: "The kernel appears to have died. It will restart automatically."
I just had the same error message appear while using Jupyter notebook. Based on what I read, I think it's suggested to reinstall pandas, NumPy and matplotlib (other libraries if necessary) and see if that works.
I had several other issues, so I reinstalled the Anaconda navigator.
You can just use py script instead of Jupyter but if you wanna use Jupyter try either reinstalling NumPy or update.
pip install -U numpy
I have successfully installed the Plotly python libraries to work with JupyterLab. I have the proper extensions installed. (All directions were followed according to: https://plot.ly/python/getting-started/ )
Most basic plots show up in my notebook file just fine, with interactivity working great! However, some plots are not appearing, and I have no idea why.
For example, the following works just fine:
import plotly.express as px
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length",
color="species", marginal_y="rug", marginal_x="histogram")
fig.show()
However, a simple scatter_matrix or parallel_coordinates shows no output. For example, the following does not work:
fig = px.scatter_matrix(df, color="species")
fig.show()
No errors appear on the console or in the output cell. The cell executes, and that's it. It doesn't show any result.
I did the following:
Updating conda: conda update --all -c plotly -c conda-forge
Cleaning and rebuilding jupyter lab extensions: jupyter lab clean and jupyter lab build.
I also tried the relevant troubleshooting options according to: https://plot.ly/python/troubleshooting/.
I tried running the notebook in regular Jupyter, and it doesn't work there either, though the start of a plot does appear, with a sad face on the plot, indicating that something is not happy, but I'm not sure what.
I tried recoding the above using the plotly.graph_objects API instead of plotly.express. Same outcome.
I still have the same problems.
It's worth noting that I CAN do the following:
fig = px.scatter_matrix(df, color="species")
fig.show(renderer='browser')
And that automatically opens the browser window and works just fine. So, it seems that the plotly engine itself is fine, there is just something up with the jupyter connection for some types of plots.
Any suggestions on where to look, or what I'm doing wrong? Thank you!
Well, after trying out a lot of different things to get this working, I finally went back and decided to just clean everything up. I did the following:
conda clean --all
conda update --all -c plotly -c defaults -c conda-forge (The order of the channel specifiers is important!)
jupyter labextension update --all
jupyter lab clean
jupyter lab build
And, I also noticed that my notebook was not trusted. So, I made the notebook trusted. And, now everything is working! There were MANY updates when I did conda update --all above because of the order that I used with the channels. I definitely put the defaults channel as higher priority, with left far fewer packages installed from conda-forge. This changed the version of a lot of packages, but I'm not certain which ones. I could look through the revisions in conda and get that list later, though packages are always being updated, so it might not be relevant.
I wondered if it was possible that setting the notebook to trusted was really the only problem? Well, I tried to clear the trust setting:
jupyter trust --reset
And, it still worked. So, I'm inclined to believe that it was not a trust issue with the notebook, but some version conflict with the numerous packages that I updated from the main conda channel defaults instead of conda-forge.
For the moment, all is well. Thanks, rpanai for chiming in.
As of late, I can't get my Matplotlib plots to show up. I have a very simple script:
import matplotlib.pyplot as plt
plt.plot([1,2,3])
but nothing ever shows up. If I include the line
plt.show()
then my Python process hangs.
In my ~/.config/matplotlib/matplotlibrc file I have
backend : MacOSX
interactive : True
I'm a little embarrassed to ask this question. I've been a Matplotlib user for many years and have never had this problem. I don't know where to begin to fix this problem. Help!
I'm using Matplotlib 2.0.0 with Python 3.5.2 from Anaconda.
The answer, as pointed out by #ImportanceOfBeingErnest is that the backend configuration for me wasn't working. I'm not sure if I need to install some additional libraries or not. I decided not to use the MacOSX backend and used the Qt5Agg backend. This worked just fine and I didn't have to install any new libraries.
I've just remove the line
interactive: True
enter code here
from my ~/matplotlib/matplotlibrc. It works fine with only backend: MacOSX using the plt.show() command.
I keep getting an error when trying to run code from one of my IPython notebooks (the notebooks themselves open up fine, I'm just unable to run any code and view the output).
The complete error is:
ERROR:tornado.access:500 POST /api/sessions (127.0.0.1) 13.01ms referrer=http://127.0.0.1:8888/notebooks/untitled0.ipynb.
I'm running Python 3.3.5, IPython 2.0.0 via an install from easy_install on a windows 8 machine.
I tried reinstalling (uninstall via pip, reinstall via easy_install) the tornado package, IPython, it was of no use.
Any help is greatly appreciated, thank you.
When I used anaconda, I met a similar problem .
Try
pip install simplejson
This works for me
This page talks about a similar problem and solution.
https://github.com/ipython/ipython/issues/1966/
Good Luck!!!
I was using Holoviews package in the IPynb and I was caught by similar error. Then I found that if try to plot a dataframe in the server rather than a "Series", this error shows up. I dont know thw complete reason for this, but to all those who are getting the similar error,
kindly change your data to Series and then plot it in server
Hope it works for you too.
Help required on matplotlib. Yes, I did not forget calling the pyplot.show().
$ ipython --pylab
import matplotlib.pyplot as p
p.plot(range(20), range(20))
It returns matplotlib.lines.Line2D at 0xade2b2c as the output.
p.show()
There is nothing to happen. No error message. No new window. Nothing. I install matplotlib by using pip and I didn't take any error messages.
Details:
I use,
Ubuntu
IPython v0.11
Python v2.6.6
matplotlib v1.0.1
If I set my backend to template in ~/.matplotlib/matplotlibrc,
then I can reproduce your symptoms:
~/.matplotlib/matplotlibrc:
# backend : GtkAgg
backend : template
Note that the file matplotlibrc may not be in directory ~/.matplotlib/. In this case, the following code shows where it is:
>>> import matplotlib
>>> matplotlib.matplotlib_fname()
In [1]: import matplotlib.pyplot as p
In [2]: p.plot(range(20),range(20))
Out[2]: [<matplotlib.lines.Line2D object at 0xa64932c>]
In [3]: p.show()
If you edit ~/.matplotlib/matplotlibrc and change the backend to something like GtkAgg, you should see a plot. You can list all the backends available on your machine with
import matplotlib.rcsetup as rcsetup
print(rcsetup.all_backends)
It should return a list like:
['GTK', 'GTKAgg', 'GTKCairo', 'FltkAgg', 'MacOSX', 'QtAgg', 'Qt4Agg',
'TkAgg', 'WX', 'WXAgg', 'CocoaAgg', 'agg', 'cairo', 'emf', 'gdk', 'pdf',
'ps', 'svg', 'template']
Reference:
Customizing matplotlib
I ran into the exact same problem on Ubuntu 12.04, because I installed matplotlib (within a virtualenv) using
pip install matplotlib
To make long story short, my advice is: don't try to install matplotlib using pip or by hand; let a real package manager (e.g. apt-get / synaptic) install it and all its dependencies for you.
Unfortunately, matplotlib's backends (alternative methods for actually rendering your plots) have all sorts of dependencies that pip will not deal with. Even worse, it fails silently; that is, pip install matplotlib appears to install matplotlib successfully. But when you try to use it (e.g. pyplot.show()), no plot window will appear. I tried all the different backends that people on the web suggest (Qt4Agg, GTK, etc.), and they all failed (i.e. when I tried to import matplotlib.pyplot, I get ImportError because it's trying to import some dependency that's missing). I then researched how to install those dependencies, but it just made me want to give up using pip (within virtualenv) as a viable installation solution for any package that has non-Python package dependencies.
The whole experience sent me crawling back to apt-get / synaptic (i.e. the Ubuntu package manager) to install software like matplotlib. That worked perfectly. Of course, that means you can only install into your system directories, no virtualenv goodness, and you are stuck with the versions that Ubuntu distributes, which may be way behind the current version...
%matplotlib inline
For me working with notebook, adding the above line before the plot works.
Just type:
plt.ion()
See https://www.youtube.com/watch?v=1zmV8lZsHF4 at 23:30 !
plt is used because of my import: import matplotlib.pyplot as plt
I'm using python2.7 on a mac with iTerm2.
For future reference,
I have encountered the same problem -- pylab was not showing under ipython. The problem was fixed by changing ipython's config file {ipython_config.py}. In the config file
c.InteractiveShellApp.pylab = 'auto'
I changed 'auto' to 'qt' and now I see graphs
What solved my problem was just using the below two lines in ipython notebook at the top
%matplotib inline
%pylab inline
And it worked. I'm using Ubuntu16.04 and ipython-5.1
Adding the following two lines before importing pylab seems to work for me
import matplotlib
matplotlib.use("gtk")
import sys
import pylab
import numpy as np
I had to install matplotlib from source to get this to work. The key instructions (from http://www.pyimagesearch.com/2015/08/24/resolved-matplotlib-figures-not-showing-up-or-displaying/) are:
$ workon plotting
$ pip uninstall matplotlib
$ git clone https://github.com/matplotlib/matplotlib.git
$ cd matplotlib
$ python setup.py install
By changing the backend, as #unutbu says, I just ran into loads more problems with all the different backends not working either.
Similar to #Rikki, I solved this problem by upgrading matplotlib with pip install matplotlib --upgrade. If you can't upgrade uninstalling and reinstalling may work.
pip uninstall matplotlib
pip install matplotlib
Be sure to have this startup script enabled :
( Preferences > Console > Advanced Options )
/usr/lib/python2.7/dist-packages/spyderlib/scientific_startup.py
If the standard PYTHONSTARTUP is enabled you won't have an interactive plot
For me the problem happens if I simply create an empty matplotlibrc file under ~/.matplotlib on macOS. Adding "backend: macosx" in it fixes the problem.
I think it is a bug: if backend is not specified in my matplotlibrc it should take the default value.
After running your code include:
import pylab as p
p.show()
if you are a nube from ruby, don't forget the parenthesis - show()
If you are working with yolov5 the fixes described here might not work as in my case. YOLOv5 developers have turned off the preview of the images using plt.show(), so most likely this will happen to you. To resolve make sure that your environment is correctly configured using requirements.txt file that comes with yolov5 and then use the workaround:
import torch
import matplotlib
model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # Load model first
matplotlib.use('TkAgg') # Change backend after loading model
as described here: https://github.com/ultralytics/yolov5/issues/2779
you can also try another backend from the ones mentioned above like 'Qt4Agg' or smth else.
I found that I needed window = Tk() and then window.mainloop()
It also shows the error when you don't call plt.plot() on anything. I got that error haha. I though I was calling it in a loop but right before the loop I overwrote my array to a blank array so it never entered the loop
For Ubuntu 12.04:
sudo apt-get install python-qt4
virtualenv .env --no-site-packages
source .env/bin/activate
easy_install -U distribute
ln -s /usr/lib/python2.7/dist-packages/PyQt4 .
ln -s /usr/lib/python2.7/dist-packages/sip.so .
pip install matplotlib