Skip to content Skip to sidebar Skip to footer

Atributeerror: 'module' Object Has No Attribute 'plt' - Seaborn

I'm very new with these libraries and i'm having troubles while plotting this: import pandas as pd import seaborn as sns import matplotlib.pyplot as plt import numpy as np import r

Solution 1:

sns.plt.show() works fine for me using seaborn 0.7.1. Could be that this is different in other versions. However, if you anyways import matplotlib.pyplot as plt you may as well simply use plt.show(), as sns.plt.show() is only working because pyplot is available inside the seaborn namespace.

Solution 2:

Well, I ran into this issue as well with Seaborn 0.8.1. Turns out being able to call sns.plt.show() is bad practice and the fact that it worked was a bug which the developer fixed. Unfortunately, there are many tutorials out there that still advise one to use sns.plt.show(). This is how I solved it:

  1. Import plt directly: import matplotlib.pyplot as plt
  2. Before you plot anything, set the default aesthetic parameters: sns.set() - important, because otherwise you won't get the Seaborn palettes.
  3. Replace all calls to sns.plt with plt

Solution 3:

As of Seaborn 0.8.1, sns.plt.plot() raises the error module 'seaborn' has no attribute 'plt'.

sns.plot() also raises an error; these methods are not in Seaborn's API.

Dropping the “sns.” to leave “plt.plot()” (as other answers suggest) does work, but only because we've called the sns.set() method in place earlier in the script... i.e. Seaborn is making an aesthetic change: Matplotlib is still the object, which does the plotting, via its plt.plot() method.

This script shows sns.set() in action... if you follow the comments and swap sns.set() between different locations in the script, it changes the appearance of the subplots. They look like Seaborn plots, but Matplotlib is doing the plotting.

Seaborn does of course have a load of its own plot methods (like sns.boxplot(), sns.violinplot() etc) but there is no longer a method sns.plt.plot().

Solution 4:

I just want to confirm that I got the same error using Jupyter inside Anaconda (Feb 2018). Got the code from here but the error occured. It turns out that I need to simply add

import matplotlib.pyplotas plt

on top of

import seaborn as sns

and it work just fine using plt.show() instead of sns.plt.show()

Solution 5:

Ensure you have updated your python shell as well IDE's like Anaconda. Like I had a constant error in Spyder (Hosted under Anaconda) with relplot and catplot until I updated Anaconda as well as seaborn (0.90). Updating via the Anaconda commandline should be pretty straightforward like in my case.

Post a Comment for "Atributeerror: 'module' Object Has No Attribute 'plt' - Seaborn"