【发布时间】:2018-12-24 09:26:50
【问题描述】:
我正在尝试获取 SciPy,但我遇到了 Unknown property density 错误,即使我从官方 SciPy documentation 复制了整个代码。
这部分工作正常:
x = np.linspace(norm.ppf(0.01), norm.ppf(0.99), 100)
ax.plot(x, norm.pdf(x), 'r-', lw=5, alpha=0.6, label='norm pdf')
rv = norm()
ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')
r = norm.rvs(size=1000)
但以下部分给了我AttributeError: Unknown property density:
ax.hist(r, density=True, histtype='stepfilled', alpha=0.2)
ax.legend(loc='best', frameon=False)
plt.show()
【问题讨论】:
-
该错误发生在
matplotlib的hist函数中。您使用的是哪个版本的matplotlib?您可以通过import matplotlib; print(matplotlib.__version__)查询。density是一个较新的参数,它取代了已弃用的normed参数。 -
我正在使用 matplotlib 1.5.1 版和后端“nbagg”。
-
我不知道哪个版本的 matplotlib 添加了
density参数,但我怀疑 1.5.1 太旧了。请改用normed=True。 -
您应该考虑在@WarrenWeckesser 下方添加您的评论作为答案。您的解决方案对我来说非常有效。
标签: python matplotlib attributeerror