Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

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

Writer Sophia Terry

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

2 Answers

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