I am trying to use `dir(sns.plt) but this results in an error:
dir(sns.plt)
Traceback (most recent call last):
File "<ipython-input-3-8072046646b0>", line 1, in <module>
dir(sns.plt)
AttributeError: module 'seaborn' has no attribute 'plt'
How do get 'plt' to show up or add it?
Please review this posting for more information on plt used with seaborn:
Seaborn plots not showing up
Related
I am trying to use seaborn's tsplot function but it is not showing an output. Instead I'm getting an error:
gammas = sns.load_dataset('gammas')
sns.tsplot(time='timepoint', # 时间数据, x轴
value='BOLD signal', # y轴value
unit='subject', # 拆分,默认参数
condition='ROI', # 分类
data=gammas
)
sns.plt.show()
The error:
"C:\Program Files\Python37\python.exe" C:/Users/42021/PycharmProjects/klyprojects/venv/plt_loss_acc.py
Traceback (most recent call last):
File "C:/Users/42021/PycharmProjects/klyprojects/venv/plt_loss_acc.py", line 137, in <module>
plot_loss_acc_seaborn()
File "C:/Users/42021/PycharmProjects/klyprojects/venv/plt_loss_acc.py", line 43, in plot_loss_acc_seaborn
sns.tsplot(time='timepoint', # 时间数据, x轴
AttributeError: module 'seaborn' has no attribute 'tsplot'
seaborn version 0.10.0 python37
Please help.
This release also removes a few previously-deprecated features:
The tsplot function and seaborn.timeseries module have been removed. Recall that tsplot was replaced with lineplot().
The seaborn.apionly entry-point has been removed.
The seaborn.linearmodels module (previously renamed to seaborn.regression) has been removed.
refer to:https://seaborn.pydata.org/whatsnew.html
seaborn-0.9.0 still has this interface.
I have tried to run the following code. but it gives an argument required error in lifelines/plotting.py file. i can't fix it .
import pandas as pd
from lifelines.datasets import load_dd
import matplotlib.pyplot as plt
data = load_dd()
print data.sample(6)
from lifelines import KaplanMeierFitter
kmf = KaplanMeierFitter()
T = data["duration"]
E = data["observed"]
kmf.fit(T, event_observed=E)
kmf.survival_function_.plot()
plt.title('Survival function of political regimes');
kmf.plot()
plt.show()
but it gives the following error
Traceback (most recent call last): File "/Users/rabindra/PycharmProjects/SurvivalAnalysis/sources/main.py", line 17, in <module>
kmf.plot() File "/Library/Python/2.7/site-packages/lifelines/plotting.py", line 331, in plot
set_kwargs_color(kwargs) File "/Library/Python/2.7/site-packages/lifelines/plotting.py", line 223, in set_kwargs_color
kwargs["ax"]._get_lines.get_next_color()) AttributeError: '_process_plot_var_args' object has no attribute 'get_next_color'
I was facing the same issue.
Upgraded lifelines to 0.14.0 and matplotlib to 2.2.2 and it works.
I am trying to make a plot of frequencies for the top 50 words from a text file but this is the error message I am getting.
s-10', 'logan', 'jacksonville', 'brokerage', 'brickman', 'mount', 'wireless', 'p
hillips', 'advisor', 'okavango', 'portfolio', 'sill', 'weddings', 'share', 'para
legal']
>>> fdist1.plot(50)
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\nltk\probability.py", line 229, in plot
import pylab
ImportError: No module named 'pylab'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python34\lib\site-packages\nltk\probability.py", line 231, in plot
raise ValueError('The plot function requires the matplotlib package (aka pyl
ab). '
ValueError: The plot function requires the matplotlib package (aka pylab). See h
ttp://matplotlib.sourceforge.net/
My professor's sample code does not say anything about importing a pylab package. I tried to download it anyways and it still doesn't seem to be working.
Any help is appreciated :)
Thanks
Plotting a distribution requires matplotlib.
See the relevant lines of FreqDist.plot():
try:
from matplotlib import pylab
except ImportError:
raise ValueError('The plot function requires matplotlib to be installed.'
'See http://matplotlib.org/')
I can import matplotlib but when I try to run the following:
matplotlib.pyplot(x)
I get:
Traceback (most recent call last):
File "<pyshell#31>", line 1, in <module>
matplotlib.pyplot(x)
AttributeError: 'module' object has no attribute 'pyplot'
pyplot is a sub-module of matplotlib which doesn't get imported with a simple import matplotlib.
>>> import matplotlib
>>> print matplotlib.pyplot
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'pyplot'
>>> import matplotlib.pyplot
>>>
It seems customary to do: import matplotlib.pyplot as plt at which time you can use the various functions and classes it contains:
p = plt.plot(...)
Did you import it? Importing matplotlib is not enough.
>>> import matplotlib
>>> matplotlib.pyplot
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'pyplot'
but
>>> import matplotlib.pyplot
>>> matplotlib.pyplot
works.
pyplot is a submodule of matplotlib and not immediately imported when you import matplotlib.
The most common form of importing pyplot is
import matplotlib.pyplot as plt
Thus, your statements won't be too long, e.g.
plt.plot([1,2,3,4,5])
instead of
matplotlib.pyplot.plot([1,2,3,4,5])
And: pyplot is not a function, it's a module! So don't call it, use the functions defined inside this module instead. See my example above
I am trying to read a *.wav file using scipy. I do the following:
import scipy
x = scipy.io.wavfile.read('/usr/share/sounds/purple/receive.wav')
As a result of this code I get:
Traceback (most recent call last):
File "test3.py", line 2, in <module>
x = scipy.io.wavfile.read('/usr/share/sounds/purple/receive.wav')
AttributeError: 'module' object has no attribute 'io'
Does anybody know what is wrong here? Thank you in advance.
As the error says, scipy module does not have 'io'.
io.wavfile is a submodule, you need to from scipy.io import wavfile and then do wavfile.read("/usr/share/sounds/purple/receive.wav")
This gives me an error with the file you are using as an example, however...