Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing Pylab/Matplotlib

I'm trying to write a program that plots a graph, which made me look into Matplotlib.

I found a tutorial that started out with this little program, that worked fine:

from pylab import *

def main():
    X = np.linspace(-np.pi, np.pi, 256, endpoint=True)
    C,S = np.cos(X), np.sin(X)
    plot(X,C)
    plot(X,S)
    show()

if __name__ == '__main__':
    main()

Then I tried to run it on another computer, where it did not work at all. I tried to download Pylab and Matplotlib. When I had installed Matplotlib it demanded something called dateutil, when I got dateutil it demanded something called six. I downloaded six, but it didn't work properly.

It doesn't feel like I'm on the right track. What should I do to get a proper installation?

EDIT:

I'm using Python 2.7 on Windows 7.

The error I get is

Traceback (most recent call last):
  File "C:\Users\Python\mscript\listdb2.py", line 19, in <module>
    from pylab import *
  File "C:\Python27\lib\site-packages\pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "C:\Python27\lib\site-packages\matplotlib\pylab.py", line 226, in <module>
    import matplotlib.finance
  File "C:\Python27\lib\site-packages\matplotlib\finance.py", line 21, in <module>
    from matplotlib.dates import date2num
  File "C:\Python27\lib\site-packages\matplotlib\dates.py", line 119, in <module>
    from dateutil.rrule import (rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY,
  File "C:\Python27\lib\site-packages\dateutil\rrule.py", line 18, in <module>
    from six import advance_iterator, integer_types
ImportError: No module named six

The file six.py is located in C:\python27\Lib\site-packages\six\six.py

The six directory also contains a file called test_six.py. If I try to run this program I also get an error:

Traceback (most recent call last):
  File "test_six.py", line 5, in <module>
    import.py
ImportError: No module named py
like image 489
user2536262 Avatar asked Aug 14 '14 13:08

user2536262


People also ask

Is PyLab part of matplotlib?

PyLab is a procedural interface to the Matplotlib object-oriented plotting library. Matplotlib is the whole package; matplotlib. pyplot is a module in Matplotlib; and PyLab is a module that gets installed alongside Matplotlib. PyLab is a convenience module that bulk imports matplotlib.

What is matplotlib PyLab Python?

Pylab is a module that provides a Matlab like namespace by importing functions from the modules Numpy and Matplotlib. Numpy provides efficient numerical vector calculations based on underlying Fortran and C binary libraries. Matplotlib contains functions to create visualizations of data.

How do I install matplotlib on Windows 10?

To install matplotlib on Windows you'll first need to install Visual Studio, which will help your system install the packages that matplotlib depends on. Go to https://dev.windows.com/, click Downloads, and look for Visual Studio Community. This is a free set of developer tools for Windows.


2 Answers

If Anaconda installed and it is already in your environment path, you can get it simply using

conda install matplotlib

in command line and then call in Python with

from pylab import *

This work for me fine as "pip install" and "easy_install" both on Win and Linux caused a lot of issues

like image 64
Andersson Avatar answered Sep 21 '22 07:09

Andersson


Installing packages on *nix is easy using pip. Pip allows you to easily install packages from the Python Package Index (PyPI) with a simple pip install matplotlib. This should install all dependencies, but if it does not then you can install them manually (for instance pip install python-dateutil).

Using pip with Windows is possible though slightly more difficult for packages that require compilers and such. However, installing Python programs on Windows is simple if you use these Windows binaries provided by Christoph Gohlke.

The particular ones for matplotlib can be found here. Note that you can also find similar binaries for python-dateutil, six, etc if necessary.

*As an aside: I would strongly suggest you look into using the full matplotlib.pyplot API rather than pylab. It's much more powerful and useful, but this is just some aside advice :) *

like image 42
Ffisegydd Avatar answered Sep 18 '22 07:09

Ffisegydd