24

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
  • 4
    Do you have the complete error message? Did you really type this code or used something else, e.g. import matplotlib as plt ? Commented Nov 16, 2017 at 8:29

2 Answers 2

39

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()
Sign up to request clarification or add additional context in comments.

1 Comment

@mark one missing part of the code was plt.show(). Anyway for some reason I am not getting the said error. Thanks
25

Try this simple step.

use pyplot using below import statement when importing matplotlib library.

import matplotlib.pyplot as plt

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.