Matplotlib 只是给出错误信息 [英] Matplotlib just giving error messages
本文介绍了Matplotlib 只是给出错误信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 Matplotlib.我以前在工作中使用过它,它运行得很好.我正在使用 IDLE 环境,我在 Matplotlib 网站上读到交互模式在 IDLE 中不起作用,但在这种情况下应该无关紧要.此外,该库似乎导入得很好:
<预><代码>>>>将 numpy 导入为 np>>>将 matplotlib 导入为 plt>>>x = np.arange(0,3 * np.pi, 0.1)>>>y = np.sin(x)>>>plt.plot(x,y)回溯(最近一次调用最后一次):文件<pyshell#7>",第 1 行,在 <module> 中plt.plot(x,y)AttributeError: 'module' 对象没有属性 'plot'>>>plt.show()回溯(最近一次调用最后一次):文件<pyshell#8>",第 1 行,在 <module> 中plt.show(x,y)AttributeError: 'module' 对象没有属性 'show' 解决方案
更改
将 matplotlib 导入为 plt
到
将 matplotlib.pyplot 导入为 plt
I am trying to use Matplotlib. I have used it here at work before and it ran just fine. I am using the IDLE environ and I read on the Matplotlib website that interactive mode does not work in IDLE, but that should not matter in this case. Also, the library seems to importing just fine:
>>> import numpy as np
>>> import matplotlib as plt
>>> x = np.arange(0,3 * np.pi, 0.1)
>>> y = np.sin(x)
>>> plt.plot(x,y)
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
plt.plot(x,y)
AttributeError: 'module' object has no attribute 'plot'
>>> plt.show()
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
plt.show(x,y)
AttributeError: 'module' object has no attribute 'show'
解决方案
Change
import matplotlib as plt
to
import matplotlib.pyplot as plt
这篇关于Matplotlib 只是给出错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文