代码之家  ›  专栏  ›  技术社区  ›  Swapnil Sagar

错误:模块“matplotlib”没有属性“plot”[重复]

  •  6
  • Swapnil Sagar  · 技术社区  · 7 年前

    我使用的是python 3.6,在运行下面的代码时,我得到的错误是
    回溯(最近一次呼叫最后一次): 文件“C:/Users/Sagar/AppData/Local/Programs/Python/Python36-32/graphfile.py”,第10行,in plt。绘图(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()
    
    2 回复  |  直到 7 年前
        1
  •  15
  •   Joseloman    7 年前

    导入语句应类似于:

     import matplotlib.pyplot as plt
    
        2
  •  0
  •   ltd9938    7 年前

    import matplotlib.pyplot as plt

    这应该行得通。您还需要导入绘图。仅仅导入matplotlib是不够的。