matplotlib does not support generators as input

独自空忆成欢 提交于 2020-06-23 03:09:35

问题


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

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


回答1:


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)


来源:https://stackoverflow.com/questions/53862456/matplotlib-does-not-support-generators-as-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!