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

18,803

The import statement should be like:

 import matplotlib.pyplot as plt
Share:
18,803
Admin
Author by

Admin

Updated on June 09, 2022

Comments

  • Admin
    Admin almost 2 years

    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()
    
  • Admin
    Admin about 6 years
    why do we haveimport pyplot?
  • Joseloman
    Joseloman about 6 years
    Because the pyplot module of matplotlib contains the necesary tools and functions for plotting. Source: matplotlib.org/api/pyplot_api.html