matplotlib不支持将生成器作为输入 [英] matplotlib does not support generators as input

查看:912
本文介绍了matplotlib不支持将生成器作为输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在此站点上运行笔记本 https://github .com/vsmolyakov/experiments_with_python/blob/master/chp01/ensemble_methods.ipynb 来练习python的集成方法,并在python 3中运行这部分代码时出错:

i am running the notebook at this site https://github.com/vsmolyakov/experiments_with_python/blob/master/chp01/ensemble_methods.ipynb to practice ensemble methods with python, and getting an error when running this part of the code in python 3:

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()

错误是"matplotlib不支持将生成器作为输入" 解决办法是什么? 最好的问候

The error is "matplotlib does not support generators as input" what is the solution? best regards

推荐答案

在该示例中 有一行num_est = map(int, np.linspace(1,100,20)).这会在python 2.7中产生一个列表.但是在python 3中,它只是一个生成器.地图还是很奇怪,所以我建议用

In that example there is a line num_est = map(int, np.linspace(1,100,20)). This produces a list in python 2.7. But in python 3 it is just a generator. The map is strange anyways, so I'd recommend to replace that line by

num_est = np.linspace(1,100,20).astype(int)

这篇关于matplotlib不支持将生成器作为输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆