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

Swapnil Sagar picture Swapnil Sagar · Jan 31, 2018 · Viewed 14k times · Source

I am using python 3.6 and while running the below code i am getting as error which says
Traceback (most recent call last): File "C:/Users/Sagar/AppData/Local/Programs/Python/Python36-32/graphfile.py", line 10, in plt.plot(x,y) AttributeError: module 'matplotlib' has no attribute 'plot'

The code is

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

Answer

Joseloman picture Joseloman · Jan 31, 2018

The import statement should be like:

 import matplotlib.pyplot as plt