Python报错之:AttributeError: 'NoneType' object has no attribute 'seq'
2018-01-21 10:28
1156 查看
在用matplotlib进行数据可视化、给图形添加标签数据标签时遇到一个报错:AttributeError: 'NoneType' object has no attribute 'seq'.
记录一下,代码:
报错:
出现这个问题是 zip(a,b) 这个里面的 a 的数组值类型不能为字符串,得为int类型,但是这里就有个问题,a 数组中的值不能转换为int类型,这个怎么处理呢?我的想法是能不能自己新建一个int类型数组,长度和 a 一样,试了一番,还真可以,改正后的代码如下:
效果图:
上面用的是 plt.annotate()的方法写标注,下面还有一种plt.text()的方法,代码如下:
效果图:
注:有写错的地方,望指教,期待与你的交流。
记录一下,代码:
from pylab import * import matplotlib.pyplot as plt a = ['a','b','c','d'] b = ['1','2','3','4'] plt.xticks(arange(len(a)),a) plt.plot(b) for xy in zip(a, b): plt.annotate(xy[1], xy=xy, xytext=(-10, 10), textcoords='offset points') plt.show()
报错:
出现这个问题是 zip(a,b) 这个里面的 a 的数组值类型不能为字符串,得为int类型,但是这里就有个问题,a 数组中的值不能转换为int类型,这个怎么处理呢?我的想法是能不能自己新建一个int类型数组,长度和 a 一样,试了一番,还真可以,改正后的代码如下:
import matplotlib.pyplot as plt a = ['a','b','c','d'] b = ['1','2','3','4'] plt.xticks(arange(len(a)),a) # 新建一个数组 c = np.arange(len(a)) plt.plot(b,marker = '.') for xy in zip(c, b): plt.annotate(xy[1], xy=xy, xytext=(-10, 10), textcoords='offset points') plt.show()
效果图:
上面用的是 plt.annotate()的方法写标注,下面还有一种plt.text()的方法,代码如下:
import matplotlib.pyplot as plt a = ['a','b','c','d'] b = ['1','2','3','4'] plt.xticks(arange(len(a)),a) # 新建一个数组 b = [int(item) for item in b] c = np.arange(len(a)) plt.plot(b,marker = '.') for i in range(len(a)): # 具体参数详情可以百度下plt.text()这个方法 plt.text(c[i],b[i],a[i]+','+str(b[i]), family='serif', style='italic', ha='right', wrap=True) plt.show()
效果图:
注:有写错的地方,望指教,期待与你的交流。
相关文章推荐
- Python: Attribute Error - 'NoneType' object has no attribute 'something'
- 用python爬github上星级排名前列的项目报错AttributeError: 'NoneType' object has no attribute 'decode'
- python __def__ Exception AttributeError: "'NoneType' object has no attribute
- python图像处理问题AttributeError: 'NoneType' object has no attribute 'shape'
- 【Python错误】AttributeError: 'bool' object has no attribute '__call__'
- Flask-JWT 小坑:No JSON object could be decoded;AttributeError: 'NoneType' object has no attribute 'get
- python opencv:AttributeError: 'module' object has no attribute 'cv' FOURCC
- Python2.X与Python3.X编程代码笔记(1):AttributeError: 'dict' object has no attribute 'iteritems'
- python运行不了 AttributeError: module object has no attribute getdefaultlocale
- [Python][转]Exception AttributeError: "'NoneType' object has no attribute
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- 【python学习笔记(2)】脚本报错"AttributeError: 'module' object has no attribute 'xxx'"解决方法
- python :TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- 解决python中问题AttributeError: 'collections.defaultdict' object has no attribute 'iteritems'
- Python Matplotlib AttributeError: 'module' object has no attribute 'popall'
- Python下Pip安装包下的AttributeError: 'Requirement' object has no attribute 'project_name'
- Python python __def__ Exception AttributeError: "'NoneType' object has no attribute
- AttributeError: 'module' object has no attribute 'AF_INET'处理办法——python
- Python3下错误AttributeError: ‘dict’ object has no attribute’iteritems‘的分析与解决