0

I want to plot but I face some errors

import numpy as np
import matplotlib as plt
x = np.arange(0, 3 * np.pi, 0.1)
y = np.sin(x)
plt.plot(x, y)
plt.show()

what is its problem?

cannot find reference 'arange' in __ init__.py I'm using pycharm on windows 10

is there any difference between matplotlib.py and matplotlib.pyplot? I can not find the second one

solved: use version 2.1.2

3 Answers3

0

Well first check the versions of your numpy and matplotlib libraries and your code:

import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 3 * np.pi, 0.1)
y = np.sin(x)
plt.plot(x, y)
plt.show()

works fine.. It gives me output like this:

enter image description here

So, maybe the problem is with your versions, Moreover, It seems that your numpy package is not installed correctly according to your error. install numpy package and then again run your code. also add matplotlib.pyplot instead or only matplotlib

Also check this: Matplotlib, Pylab, Pyplot, etc: What's the difference between these and when to use each?

Hope this will help you! :)

Community
  • 1
  • 1
Abdullah Ahmed Ghaznavi
  • 1,978
  • 3
  • 17
  • 27
0

Your import of matplotlib is not correct. Use import matplotlib.pyplot as plt (notice the extra .pyplot in there)

It'll should run properly.

MattB
  • 520
  • 3
  • 12
0

the problem was with my version of matplotlib I've installed v.2.2.0. uninstalled it and installed v.2.1.2 then this code start working.