Attributeerror: Module 'Matplotlib' Has No Attribute 'Plot'

I am using python 3.6 and a learner. Below is a simple code of a sin wave.

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.

1

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.

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

Try this simple step.

use pyplot using below import statement when importing matplotlib library.

import matplotlib.pyplot as plt

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest