AttributeError: module 'seaborn' has no attribute 'tsplot' - python

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.

Related

Python and matplotlib: when I try to import, it send a not valid cycler construction error

I've wanted to try matplotlib for the first time but when I import it, there is an error.
The only line of my code is:
from matplotlib import pyplot as plt
but when I run this, I have this error:
Traceback (most recent call last):
File "/Users/mylaptop/Desktop/main.py", line 1, in <module>
from matplotlib import pyplot as plt
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/matplotlib/__init__.py", line 903, in <module>
rcParamsDefault = _rc_params_in_file(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/matplotlib/__init__.py", line 834, in _rc_params_in_file
config[key] = val # try to convert to proper type or raise
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/matplotlib/__init__.py", line 678, in __setitem__
raise ValueError(f"Key {key}: {ve}") from None
ValueError: Key axes.prop_cycle: 'cycler('color', ['1f77b4', 'ff7f0e', '2ca02c', 'd62728', '9467bd', '8c564b', 'e377c2', '7f7f7f', 'bcbd22', '17becf'])' is not a valid cycler construction: name 'np' is not defined
I have no idea on how to fix it.
I am on Mac and I use the Pycharm IDE.
Looking at the code of matplotlib/__init__.py, the Python library numpy is a requirement of matplotlib, but the error:
name 'np' is not defined
seems to tell us that it's not (correctly) installed in your system.

'tensorflow' has no attribute 'config' error

I am trying to run the following lines:
import tensorflow as tf
physical_devices = tf.config.list_physical_devices("GPU")
for i in range(len(physical_devices)):
tf.config.experimental.set_memory_growth(physical_devices[i], True)
I am trying to run this lines too:
import tensorflow as tf
physical_devices = tf.test.gpu_device_name("GPU")
for i in range(len(physical_devices)):
tf.config.experimental.set_memory_growth(physical_devices[i], True)
But the first method errors out like this:
Traceback (most recent call last):
File "main_train.py", line 4, in <module>
physical_devices = tf.config.list_physical_devices("GPU")
AttributeError: module 'tensorflow' has no attribute 'config'
And the second method errors out like this:
Traceback (most recent call last):
File "main_train.py", line 5, in <module>
for i in range(len(tf.test.gpu_device_name("GPU"))):
AttributeError: module 'tensorflow' has no attribute 'test'
I am using Tensorflow 2.4.0 .Any ideas what I'm doing wrong?
If anyone could help that would be great:)
Thank's for every help in advance:)
I read that you already fixed it but since you didn't included it in your post here is the solution everyone else having this error: you need to change some modules from e.g. tf.config.list_physical_devices("GPU") to tf.compat.v1.config.list_physical_devices("GPU"). By adding ".compat.v1" you are ensuring backwards capability. You can use this code snippet for all other modules, that don't work.

What kind of object do I need to use the options parameter of fix_multiple_files?

I need to create a simple script for fixing indentation in python scripts of the repository. I found fix_multiple_files in autopep8 module:
import autopep8
autopep8.fix_multiple_files('/home/playrix/work/ci-teamcity/scripts/', options={'recursive': 1})
I'm getting this every time I run the script:
Traceback (most recent call last):
File "/home/playrix/work/ci-teamcity/scripts/1.py", line 4, in <module>
autopep8.fix_multiple_files('/home/playrix/work/ci-teamcity/scripts/', options='')
File "/home/playrix/.local/lib/python2.7/site-packages/autopep8.py", line 3897, in fix_multiple_files
filenames = find_files(filenames, options.recursive, options.exclude)
AttributeError: 'str' object has no attribute 'recursive'
How correctly noticed johnsharpe it was argparse.Namespace. And the best way to get it was:
opt = autopep8.parse_args(arguments=['recursive', '--in-place', '--aggressive'])

AttributeError: 'module' object has no attribute 'Template'

I'm using MacOs with the PyCharm environment, and my project is set to use Python 2.7.10. Now, I have on the first line of my module the line:
import numpy as np
When I try to run my code, I get the following error:
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /{path to file}/numpy_exercise.py
Traceback (most recent call last):
File "/{path to file}/numpy_exercise.py", line 1, in module>
import numpy as np
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/__init__.py", line 169, in module>
from . import polynomial
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/polynomial/__init__.py", line 20, in module>
from .polynomial import Polynomial
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/polynomial/polynomial.py", line 68, in module>
from .polytemplate import polytemplate
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/polynomial/polytemplate.py", line 17, in module>
polytemplate = string.Template(''' AttributeError: 'module' object has no attribute 'Template'
(note that "module>" was actually in brackets from both sides but because it gets omitted that way I daleted the first bracket so you can see it)
Though in Python 3 it does not happens to me. I looked on the web but couldn't find anything. I have no clue of why this is happening. I'd be glad to get some of your help!
Thank you guys!

ReadTheDocs will not autogenerate API documentation for a project that uses Matplotlib

I am able to use Sphinx to auto generate my project's API documentation locally, but I run into trouble when I try to use ReadTheDocs. When ReadTheDocs builds the documentation, the API pages are all blank (see this, for example). After I read this blog entry, I realized the solution is to mock things like numpy and matplotlib. So I added the following line to my conf.py
autodoc_mock_imports = ['numpy', 'matplotlib', 'matplotlib.pyplot', 'matplotlib.patches', 'matplotlib.path', 'matplotlib.lines', 'matplotlib.text', 'matplotlib.transforms', 'matplotlib.artist', 'cpickle']
With that addition, I cannot build the API documentation locally or on ReadTheDocs, because of the following two Sphinx issues.
Issue #1:
When I build the documentation I get the following error.
/Users/Ben/Documents/Python/clearplot/doc/source/api/clearplot.rst:19: WARNING: autodoc: failed to import module u'clearplot'; the following exception was raised:
Traceback (most recent call last):
File "/Users/Ben/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/sphinx/ext/autodoc.py", line 385, in import_object
__import__(self.modname)
File "/Users/Ben/Documents/Python/clearplot/clearplot/__init__.py", line 33, in <module>
mpl_version = _parse_version_string(_mpl.__version__)
File "/Users/Ben/Documents/Python/clearplot/clearplot/__init__.py", line 19, in _parse_version_string
v_list = v.split(".")
AttributeError: type object '__version__' has no attribute 'split'
I have confirmed that this error comes from simply doing matplotlib.__version__.split("."). I couldn't figure out how to solve this issue quickly so I commented it out.
Issue #2:
Now, I get the following error when I build the documentation.
/Users/Ben/Documents/Python/clearplot/doc/source/api/clearplot.rst:19: WARNING: autodoc: failed to import module u'clearplot'; the following exception was raised:
Traceback (most recent call last):
File "/Users/Ben/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/sphinx/ext/autodoc.py", line 385, in import_object
__import__(self.modname)
File "/Users/Ben/Documents/Python/clearplot/clearplot/__init__.py", line 45, in <module>
import params
File "/Users/Ben/Documents/Python/clearplot/clearplot/params.py", line 19, in <module>
_mpl.rcParams['backend'] = 'Qt4Agg'
TypeError: '_MockModule' object does not support item assignment
If I comment out the offending line (_mpl.rcParams['backend'] = 'Qt4Agg'), I get the same error for the next line because my params module is full of assignments to the matplotlib.rcParams dictionary.
Both of these issues look like a pain to fix. Is there a better way? If not, how should I solve Issue #1 and #2?
From reading this it looks like there is a work around for using dictionaries with mock. Should I search for a similar solution for using something as basic as the string that comes from matplotlib.__version__?
In case it helps, the code on github is here.

Categories