1

In Eclipse, I tried import "matplotlib", but it didn't work.

Traceback (most recent call last):
File "C:\Users\Hunter-\Desktop\A_Cognitive\neural_network\step_function.py", 
line 2, in <module>
import matplotlib.pylab as plt
ImportError: No module named matplotlib.pylab

mycode is below

import numpy as np
import matplotlib.pylab as plt
def step_funtion(x):
return np.array(x>0,dtype=np.int)
x=np.arange(-5.0,5.0,0.1)
y=step_funtion(x)
plt.plot(x,y)
plt.ylim(-0.1,1.1)
plt.show

※I checked by Windows cmd "WHERE", and finally I gets result of exsist of matplotlib's file.↓   >WHERE /r C:\ProgramData\Anaconda2 matplotlib.* _  

C:\ProgramData\Anaconda2\pkgs\anaconda-navigator-1.9.2-py27_0\Lib\site- 
  packages\anaconda_navigator\static\images\logos\matplotlib.png
C:\ProgramData\Anaconda2\pkgs\matplotlib-2.2.3-py27h263d877_0\Lib\site- 
  packages\matplotlib\mpl-data\images\matplotlib.pdf
C:\ProgramData\Anaconda2\pkgs\matplotlib-2.2.3-py27h263d877_0\Lib\site- 
  packages\matplotlib\mpl-data\images\matplotlib.png
C:\ProgramData\Anaconda2\pkgs\matplotlib-2.2.3-py27h263d877_0\Lib\site- 
  packages\matplotlib\mpl-data\images\matplotlib.ppm
C:\ProgramData\Anaconda2\pkgs\matplotlib-2.2.3-py27h263d877_0\Lib\site- 
  packages\matplotlib\mpl-data\images\matplotlib.svg
C:\ProgramData\Anaconda2\pkgs\spyder-3.3.1-py27_1\Lib\site- 
  packages\spyder\images\matplotlib.png
Helpful
  • 11
  • 6
  • 1
    pylab is [generally discouraged](https://stackoverflow.com/a/11471777/4799172). It wouldn't surprise me if they simply removed it in the meantime. – roganjosh Nov 21 '18 at 12:55
  • 2
    @roganjosh No pylab still exists. It wasn't removed. It's discouraged, but many people like it, so it stays. – ImportanceOfBeingErnest Nov 21 '18 at 12:58
  • 1
    @helpful Can you check if you can import matplotlib alone, `import matplotlib` ? If so, what does `print(matplotlib.__version__)` give? If not, you need to install matplotlib – ImportanceOfBeingErnest Nov 21 '18 at 13:08
  • @ImportanceOfBeingErnest Thx 4 ur kindness. Idk how to check whether it is or not. Is this way wrong?→ import os.path print(os.path.isfile("matplotlib")) The result was false. – Helpful Nov 21 '18 at 13:34
  • @ImportanceOfBeingErnest Finally I checked by Windows cmd and then the file probably nothing. The result is written on my question on Top in this page↑ What should I next? – Helpful Nov 21 '18 at 14:49
  • It looks like you have not installed matplotlib. Anaconda navigator should allow you to do that quite easily. – ImportanceOfBeingErnest Nov 21 '18 at 15:31
  • @ImportanceOfBeingErnest THX. I'll try it work. – Helpful Nov 21 '18 at 17:00

1 Answers1

0

I think you meant:

import matplotlib.pyplot as plt
Joe
  • 12,057
  • 5
  • 39
  • 55
  • thx answer, but it also doesn't work^^;; Traceback (most recent call last): File "C:\Users\Hunter-\Desktop\A_Cognitive\neural_network\step_function.py", line 2, in import matplotlib.pyplot as plt ImportError: No module named matplotlib.pyplot – Helpful Nov 21 '18 at 13:19
  • have you checked if `matplotlib` is installed? – Joe Nov 21 '18 at 13:22
  • Thx 4 ur repling. Now I'm tring it but Idk how to check its exist. Is this way wrong?→import os.path print(os.path.isfile("matplotlib")) This result was false. – Helpful Nov 21 '18 at 13:37
  • try with: `import sys` `print 'matplotlib' in sys.modules` – Joe Nov 21 '18 at 13:41
  • Finally I checked by Windows cmd and then the file probably nothing. The result is written on my question on Top in this page↑ – Helpful Nov 21 '18 at 14:38
  • What should I next? – Helpful Nov 21 '18 at 14:50
  • Maybe Eclipse Is running another python enviroment. Check if It Is the right one – Joe Nov 21 '18 at 15:09