Python matplotlib.show() 错误:模块“matplotlib”没有属性“show”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45150238/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error with matplotlib.show() : module 'matplotlib' has no attribute 'show'
提问by William
I'm a Python 3.6 user and I've been trying to learn how to use the matplotlib and pandas libraries. But as I try to use the "show()" function, I get the following error:
我是 Python 3.6 用户,我一直在尝试学习如何使用 matplotlib 和 pandas 库。但是当我尝试使用“show()”函数时,出现以下错误:
import pandas as pd
import matplotlib as plt
df=pd.DataFrame({'Day':[1,2,3], 'Revenue':[100,200,320]})
df.plot()
plt.show()
ERROR: AttributeError: module 'matplotlib' has no attribute 'show'
错误:AttributeError:模块“matplotlib”没有属性“show”
回答by Rory Daulton
Do not use
不使用
import matplotlib as plt
but rather use
而是使用
import matplotlib.pyplot as plt
plt
is an abbreviation for pyplot
, which is a module inside the matplotlib
package. You need to address it for the kinds of things you are doing, not just matplotlib
.
plt
是 的缩写pyplot
,是matplotlib
包内的一个模块。你需要针对你正在做的事情来解决它,而不仅仅是matplotlib
.
Note that matplotlib
can be used without using pyplot
at all, but most people find it easier to use pyplot
. See its documentationor the tutorialfor details.
请注意,matplotlib
可以在不使用的情况下使用pyplot
,但大多数人发现使用pyplot
. 有关详细信息,请参阅其文档或教程。