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)

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lhyangtop

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值