Module Seaborn has no attribute '<any graph>'

家住魔仙堡 提交于 2019-12-20 09:53:19

问题


I am having trouble switching from ggplot2 into seaborn. Currently using Anaconda v. 4.5.8 and Python 3.6.3

Any graph I use cannot be found. For example I can take any code from seaborn's site and run:

import matplotlib as plt
import seaborn as sns
sns.set(style="ticks")

dots = sns.load_dataset("dots")

# Define a palette to ensure that colors will be
# shared across the facets
palette = dict(zip(dots.coherence.unique(),
                   sns.color_palette("rocket_r", 6)))

# Plot the lines on two facets
sns.relplot(x="time", y="firing_rate",
            hue="coherence", size="choice", col="align",
            size_order=["T1", "T2"], palette=palette,
            height=5, aspect=.75, facet_kws=dict(sharex=False),
            kind="line", legend="full", data=dots)
sns.plt.show() #this was not on site code but tried it(plt.show() as referenced by other posts)

Error message:

  File "<ipython-input-8-893759310442>", line 13, in <module>
    sns.relplot(x="time", y="firing_rate",

AttributeError: module 'seaborn' has no attribute 'relplot'

Looked at these posts( among others)

(1) AtributeError: 'module' object has no attribute 'plt' - Seaborn

(2) Seaborn ImportError: DLL load failed: The specified module could not be found

(3) ImportError after successful pip installation

(4) Error importing Seaborn module in Python

and tried the install/uninstall methods they described ( python -m pip install seaborn, uninstall seaborn/ reinstall - etc.) I did this in both conda using conda and cmd using pip.

I haven't spent much time with PATHs but here are screenshots:

Any ideas?

Many Thanks


回答1:


You have found that example on the newest version of the seaborn module, which is 0.9. From the "What’s new in each version" section:

New relational plots

Three completely new plotting functions have been added: relplot(), scatterplot(), and lineplot()

So, you need to update your seaborn to the latest version to use these plotting functions.




回答2:


I had this same issue. The selected answer, is correct, you have an older version, but there were a few hangups that I ran into. Here's what happened and how I corrected it. I first tried:

conda update seaborn

which did not install seaborn 0.9.0, but rather installed a 0.8.x version. I then did

conda remove seaborn
conda install seaborn=0.9.0

which still installed an older version. I finally got it to work using pip3

pip3 install seaborn==0.9.0

Which worked properly and solved the missing plots you mentioned. As long as you do this within your conda environment, it should function as though it was a conda install.




回答3:


First uninstall seaborn:

conda remove seaborn
pip uninstall seaborn

Then try download and install lastest version:

pip3 --no-cache-dir install seaborn

It worked for me.



来源:https://stackoverflow.com/questions/51402579/module-seaborn-has-no-attribute-any-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!