Matplotlib works perfectly, pylab doesn’t

I installed both Pylab and Matplotlib the other day to test out graphic visualizations of data in Python, but I ran into a minor problem that I'm hoping to have clarified. It seems like Pylab commands don't want to work at all, while the same commands in Matplotlib work perfectly fine.

For example, this simple code:

from matplotlib.pyplot import plot,show
y = [ 1.0, 2.4, 1.7, 0.3, 0.6, 1.8 ]
plot(y)
show()

works fine. I run it in the IDE I'm using (IDLE 3.8.5) and the program outputs a lovely little graph. On the other hand, this version of the code:

from pylab import plot,show
y = [ 1.0, 2.4, 1.7, 0.3, 0.6, 1.8 ]
plot(y)
show()

yields the following error message:

Traceback (most recent call last):
  File "C:\Users\kevin\Desktop\Coding\test.py", line 1, in <module>
    from pylab import plot,show
ImportError: cannot import name 'plot' from 'pylab' (C:\Users\kevin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pylab\__init__.py)

I've been testing out other relevant commands as well, with the same result: works in Matplotlib, doesn't work in Pylab. I know for a fact that this code can work, because it's the same one that my textbook and professor demonstrated the other day and it worked for them. In fact, I actually asked my professor about it and he wasn't sure what the problem was either, since I've installed the newest versions of everything not that long ago. He suggested the possibility that perhaps Pylab itself is no longer supported anymore, but I couldn't find any information about this at all on the internet.

This isn't the biggest problem in the world, as I can obviously just always use Matplotlib and never touch Pylab, but I feel it's still worth verifying why this is happening in the first place, in case it causes me problems in the future.



Read more here: https://stackoverflow.com/questions/64405172/matplotlib-works-perfectly-pylab-doesnt

Content Attribution

This content was originally published by K.T.B. at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: