Error: module 'matplotlib' has no attribute 'plot'

Error: module 'matplotlib' has no attribute 'plot'

我正在使用 python 3.6,而 运行 下面的代码我得到的错误是
追溯(最近一次通话): 文件 "C:/Users/Sagar/AppData/Local/Programs/Python/Python36-32/graphfile.py",第 10 行,位于 plt.plot(x,y) AttributeError: 模块 'matplotlib' 没有属性 'plot'

密码是

import matplotlib as plt
x=[]
y=[]
readfile=open("graph.txt","r")
data=readfile.read().split("\n")
for i in data:
     val=i.split(",")
     x.append(int(val[0]))
     y.append(int(val[1]))
plt.plot(x,y)
plt.show()

import matplotlib.pyplot as plt

这应该有效。您还需要导入图。仅仅导入 matplotlib 是不够的。

导入语句应该是这样的:

 import matplotlib.pyplot as plt