Using seaborn's documentation code to generate a lineplot returns an AttributeError: 'module' object has no attribute 'lineplot'. I have updated seaborn and reimported the module and tried again, no luck. Did lineplot get retired, or is there something else going on?
import seaborn as sns; sns.set()
import matplotlib.pyplot as plt
fmri = sns.load_dataset("fmri")
ax = sns.lineplot(x="timepoint", y="signal", data=fmri)
If you are using conda, you need to install seaborn with the version specified:
conda install -c anaconda seaborn=0.9.0
Once your seaborn 0.9.0 is installed properly, you should be able to use the lineplot function (at least it works on mine).
That way you don't have to go outside of the conda ecosystem and use seaborn with pip.
Lineplot works with update to seaborn 0.9. conda has not yet integrated seaborn 0.9.0 into it's default channel, which is why the update to 0.9 failed on my first go.
Couldn't Update Seaborn via Default Channel but found another way to do it through this answer
As other's said before, you need seaborn version 0.9.0 (or above will work too, I guess). The pip-way of doing this without conda is:
pip install seaborn==0.9.0
My problem was that I had an older version ( 0.8.x) installed, so simply running pip install seaborn doesn't help in that case.
Alternatively, you can directly upgrade to the latest version of seaborn like this:
pip install -U seaborn
Within Jupyter notebook you can run the install without leaving the notebook.
You only have to add the tag "y" to install the package.
!conda install -y -c anaconda seaborn=0.9.0
Related
I keep getting the error: ModuleNotFoundError: No module named 'seaborn'
when trying to import seaborn.
I have installed seaborn using both pip install seaborn and conda install seaborn.
I saw on seaborn that I am not the only one who has had this issue, but I have not been able to resolve this problem, how can I check and updated that my pip/conda points to the same installation as my interpreter?
EDIT:
I have tried running !pip install seaborn in the notebook, but this still does not work. I have also created my own conda env and installed seaborn (it shows base in the photos) but this also did not work.
you might have an old version of Jupyter notebook, so need to try this command to install it in the current kernel.
import sys
!{sys.executable} -m pip install seaborn
In the New Jupyter version (2019) can be installed simply as:
%pip install seaborn
Note: Answer from different question!
Here my problem:
sns.scatterplot(x=[x,x,x], y=[x,x,x])
AttributeError: module 'seaborn' has no attribute 'scatterplot'
I read that seaborn needs to be updated, to solve this. So I did:
!pip install seaborn --upgrade #or also !pip install seaborn==0.9.0
import seaborn as sns
sns.__version__
0.8.1
It's not updating, and I keep getting the same AttributeError. What am I missing?
Update jupyter notebook in the Anaconda navigator. All modules will get updated. This should resolve your issue.
I just used Anaconda Prompt to update seaborn.
pip install seaborn --upgrade
and then I restarted Anaconda and it works now.
Bests,
I experienced the same issues after upgrading seaborn but it worked just fine once I restarted my kernel.
I've installed a virtualenv with pyenv using Python v2.7.12. Inside this virtualenv, I installed matplotlib v1.5.1 via:
pip install matplotlib
with no issues. The problem is that a simple
import matplotlib.pyplot as plt
plt.scatter([], [])
plt.show()
script fails to produce a plot window. The backend that I see in the virtualenv using:
import matplotlib
print matplotlib.rcParams['backend']
is agg, which is apparently the root cause of the issue. If I check the backend in my system-wide installation, I get Qt4Agg (and the above script when run shows a plot window just fine).
There are already several similar questions in SO, and I've tried the solutions given in all of them.
Matplotlib plt.show() isn't showing graph
Tried to create the virtualenv with the --system-site-packages option. No go.
How to ensure matplotlib in a Python 3 virtualenv uses the TkAgg backend?
Installed sudo apt install tk-dev, then re-installed using pip --no-cache-dir install -U --force-reinstall matplotlib. The backend still shows as agg.
Matplotlib doesn't display graph in virtualenv
Followed install instructions given in this answer, did nothing (the other answer involves using easy_install, which I will not do)
matplotlib plot window won't appear
The solution given here is to "install a GUI library (one of Tkinter, GTK, QT4, PySide, Wx)". I don't know how to do this. Furthermore, if I use:
import matplotlib.rcsetup as rcsetup
print(rcsetup.all_backends)
I get:
[u'GTK', u'GTKAgg', u'GTKCairo', u'MacOSX', u'Qt4Agg', u'Qt5Agg', u'TkAgg', u'WX', u'WXAgg', u'CocoaAgg', u'GTK3Cairo', u'GTK3Agg', u'WebAgg', u'nbAgg', u'agg', u'cairo', u'emf', u'gdk', u'pdf', u'pgf', u'ps', u'svg', u'template']
meaning that all those backends are available in my system (?).
matplotlib does not show my drawings although I call pyplot.show()
My matplotlibrc file shows the line:
backend : Qt4Agg
I don't know how to make the virtualenv aware of this?
Some of the solutions involve creating links to the system version of matplotlib (here and here), which I don't want to do. I want to use the version of matplotlib installed in the virtualenv.
If I try to set the backend with:
import matplotlib
matplotlib.use('GTKAgg')
I get ImportError: Gtk* backend requires pygtk to be installed (same with GTK). But if I do sudo apt-get install python-gtk2 python-gtk2-dev, I see that they are both installed.
Using:
import matplotlib
matplotlib.use('Qt4Agg')
(or Qt5Agg) results in ImportError: Matplotlib qt-based backends require an external PyQt4, PyQt5, or PySide package to be installed, but it was not found. Not sure if I should install some package?
Using:
import matplotlib
matplotlib.use('TkAgg')
results in ImportError: No module named _tkinter, but sudo apt-get install python-tk says that it is installed.
Using:
import matplotlib
matplotlib.use('GTKCairo')
results in ImportError: No module named gtk. So I try sudo apt-get install libgtk-3-dev but it says that it already installed.
How can I make the virtualenv use the same backend that my system is using?
You can consider changing your backend to TkAgg in the Python 2 virtualenv by running the following:
sudo apt install python-tk # install Python 2 bindings for Tk
pip --no-cache-dir install -U --force-reinstall matplotlib # reinstall matplotlib
To confirm the backend is indeed TkAgg, run
python -c 'import matplotlib as mpl; print(mpl.get_backend())'
and you should see TkAgg.
I'm using spyder (python2.7) on a macbook for my data analysis
import seaborn as sis
but when I run:
ImportError: No module named seaboard
I installed seaborn using conda install seaborn and also pip2.7, but still having trouble in spyder. If run in terminal as python2.7 file.pyit works, so I guess I'm not able to import seaborn correctly in spyder.
PS:
I've also tried adding the right path where the package is located into python path manager.....
Thank you very much
Conda install:
http://conda.pydata.org/miniconda.html
conda install seaborn
You should use conda for easy step, or follow this tutorial:
https://stanford.edu/~mwaskom/software/seaborn/installing.html
I'm using Python 2.7.3 in 64-bit. I installed pandas as well as matplotlib 1.1.1, both for 64-bit. Right now, none of my plots are showing. After attempting to plot from several different dataframes, I gave up in frustration and tried the following first example from http://pandas.pydata.org/pandas-docs/dev/visualization.html:
INPUT:
import matplotlib.pyplot as plt
ts = Series(randn(1000), index=date_range ('1/1/2000', periods=1000))
ts = ts.cumsum()
ts.plot()
pylab.show()
OUTPUT:
Axes(0.125,0.1;0.775x0.8)
And no plot window appeared. Other StackOverflow threads I've read suggested I might be missing DLLs. Any suggestions?
I'm not convinced this is a pandas issue at all.
Does
import matplotlib.pyplot as plt
plt.plot(range(10))
plt.show()
bring up a plot?
If not:
How did you install matplotlib? Was it from source or did you install it from a package manager/pre-built binary?
I suspect that if you run:
import matplotlib
print matplotlib.rcParams['backend']
The result will be a non-GUI backend (almost certainly "Agg"). This suggests you don't have a suitable GUI toolkit available (I personally use Tkinter which means my backend is reported as "TkAgg").
The solution to this depends on your operating system, but if you can install a GUI library (one of Tkinter, GTK, QT4, PySide, Wx) then pyplot.show() should hopefully pop up a window for you.
HTH,
I had this problem when working from within a virtualenv.
Cause
The cause of the problem is that when you pip install matplotlib, it fails to find any backends (even if they are installed on your machine), so it uses the "agg" backend, which does not make any plots, just writes files. To confirm that this is the case, go: python -c "import matplotlib; print matplotlib.get_backend()", you probably see agg.
I could however, successfully use matplotlib on the system (outside the virtualenv). I also failed to install PySide, PyQt, or get it to work for TkAgg, for various different reasons.
Solution
I eventually just made a link to my system version of matplotlib (starting from outside the venv):
...$ pip install matplotlib
...$ cd /to/my/venv/directory
...$ source venv/bin/activate
(venv) .... $ pip uninstall matplotlib
(venv) .... $ ln -s /usr/lib/pymodules/python2.7/matplotlib $VIRTUAL_ENV/lib.python*/site-packages
After that, I could use matplotlib and the plots would show. Your local version of matplotlib may be in a different place. To see where it is, go (outside of the venv, in python)
...$ python -c 'import matplotlib; matplotlib.__file__'
Try installing these libraries, it works for me:
$ sudo apt-get install tcl-dev tk-dev python-tk python3-tk