Python AttributeError: 模块 'matplotlib' 没有属性 'plot'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47324756/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
AttributeError: module 'matplotlib' has no attribute 'plot'
提问by X10nD
I am using python 3.6 and a learner. Below is a simple code of a sin wave.
我正在使用 python 3.6 和一个学习者。下面是一个正弦波的简单代码。
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-10 , 10, 100)
y = np.sin(x)
plt.plot(x, y, marker="x")
I am receiving the error "AttributeError: module 'matplotlib' has no attribute 'plot'" Any help would be appreciated.
我收到错误“AttributeError: module 'matplotlib' has no attribute 'plot'” 任何帮助将不胜感激。
回答by Mark Schuurman
Have you installed matplotlib properly? I added an extra line to your code to show the plot. This code works properly in Visual Studio after installing the matplotlib library.
您是否正确安装了 matplotlib?我在您的代码中添加了额外的一行以显示情节。安装 matplotlib 库后,此代码在 Visual Studio 中正常工作。
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-10 , 10, 100)
y = np.sin(x)
plt.plot(x, y, marker="x")
plt.show()