pandas和matplotlib一起使用提示nonetype
import pandas
import seaborn
import matplotlib.pyplot as code
speed = [0.1, 17.5, 40, 48, 52, 69, 88]
lifespan = [2, 8, 70, 1.5, 25, 12, 28]
index = ['snail', 'pig', 'elephant',
'rabbit', 'giraffe', 'coyote', 'horse']
df = pandas.DataFrame([11,2,2],[2,3,4])
print(df)
seaborn.boxenplot(x=speed,y=lifespan)
code.bar(speed,lifespan)
code.show()
```勿粘贴截图
###### 运行结果及报错内容
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\numpy\core\getlimits.py", line 462, in __new__
dtype = numeric.dtype(dtype)
TypeError: 'NoneType' object is not callable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2021.3.2\plugins\python\helpers\pydev\pydevd.py", line 1483, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files\JetBrains\PyCharm 2021.3.2\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "E:/CODE/playwright/go.py", line 11, in <module>
seaborn.boxenplot(x=speed,y=lifespan)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\seaborn\_decorators.py", line 46, in inner_f
return f(**kwargs)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\seaborn\categorical.py", line 2642, in boxenplot
plotter.plot(ax, kwargs)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\seaborn\categorical.py", line 2065, in plot
self.draw_letter_value_plot(ax, boxplot_kws)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\seaborn\categorical.py", line 2061, in draw_letter_value_plot
ax.autoscale_view(scalex=self.orient == "h", scaley=self.orient == "v")
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\axes\_base.py", line 2935, in autoscale_view
handle_single_axis(
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\axes\_base.py", line 2895, in handle_single_axis
x0, x1 = locator.nonsingular(x0, x1)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\ticker.py", line 1654, in nonsingular
return mtransforms.nonsingular(v0, v1, expander=.05)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\transforms.py", line 2880, in nonsingular
if maxabsvalue < (1e6 / tiny) * np.finfo(float).tiny:
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\numpy\core\getlimits.py", line 465, in __new__
dtype = numeric.dtype(type(dtype))
TypeError: 'NoneType' object is not callable
###### 我的解答思路和尝试过的方法
禁用pandas相关的语句就可以了
```python
import pandas
import seaborn
import matplotlib.pyplot as code
speed = [0.1, 17.5, 40, 48, 52, 69, 88]
lifespan = [2, 8, 70, 1.5, 25, 12, 28]
index = ['snail', 'pig', 'elephant',
'rabbit', 'giraffe', 'coyote', 'horse']
#df = pandas.DataFrame([11,2,2],[2,3,4])
#print(df)
seaborn.boxenplot(x=speed,y=lifespan)
code.bar(speed,lifespan)
code.show()
使用pandas中的数据进行画图,直接使用数据或者间接使用数据均可以
你的代码我运行是没有报错的。不知道是不是pandas版本的问题。我的pandas是1.4.1