Python总结:RuntimeError: matplotlib does not support generators as input
生活随笔
收集整理的这篇文章主要介绍了
Python总结:RuntimeError: matplotlib does not support generators as input
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
QUESTION:RuntimeError: matplotlib does not support generators as input?
ANSWER:
例子:
来源:stackoverflow:question
在运行github上的一个例子时,https://github.com/vsmolyakov/experiments_with_python/blob/master/chp01/ensemble_methods.ipynb,
进行代码检测,报错了使用Python3.x版本。
plt.figure() (_, caps, _) = plt.errorbar(num_est, bg_clf_cv_mean, yerr=bg_clf_cv_std, c='blue', fmt='-o', capsize=5) for cap in caps:cap.set_markeredgewidth(1) plt.ylabel('Accuracy'); plt.xlabel('Ensemble Size'); plt.title('Bagging Tree Ensemble'); plt.show()实际上在这个例子中,有一行num_est = map(int, np.linspace(1,100,20)),这个在Python的2.7版本中产生的是一个List,而在Python3.x中产生的是一个Generators,所有建议把这一个替换成:
num_est = np.linspace(1,100,20).astype(int)
总结
以上是生活随笔为你收集整理的Python总结:RuntimeError: matplotlib does not support generators as input的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 单链表介绍及其实现
- 下一篇: Python中参数函数内部赋值与使用+=