Howto: Install matplotlib on Ubuntu 10.04.1

matplotlib is a python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms.
— from the official introduction.

This article shows how to install matplotlib from source code on Ubuntu 10.04.1. Read on to find why we have to go from source code, instead of using ‘apt-get’ or ‘Ubuntu software center’.

Build and install matplotlib with source code.

From the official installation guide, we can know, the basic requirements are:

  • Python
  • numpy
  • libpng
  • freetype

With a freshly built Ubuntu 10.04.1, Python2.6, libpng12, libfreetype6 are already installed.

So we need to install numpy, simply using “apt-get”.

sudo apt-get install python-numpy

What the official documentation is missing is that, the following things:

  • python2.6-dev
  • libpng12-dev
  • libfreetype6-dev

are also requied, because Python needs the header files and static libraries to build matplotlib from source.

Install them too.

sudo apt-get install python2.6-dev
sudo apt-get install libpng12-dev
sudo apt-get install libfreetype6-dev.

Now, it’s ready to build and install matplotlib.

Download it (version 1.0.0 or higher) from the official website. Then build and install it.

tar zxvf matplotlib-1.0.0.tar.gz
cd matplotlib-1.0.0
python setup.py build
sudo python setup.py install

It’s done!

Read on to find out why we have to install from source code.

Why not use the default/well-known/recommended installing?

The following two easier ways are preferred for most softwares provided by Ubuntu, but are not for matplotlib. The only reason is that, they give you a matplotlib installation that is ‘too old‘.

1) Use Ubuntu software center.

First, open the ‘Ubuntu software center’.

Then, search for ‘matplotlib’.

The last thing to do is to click the “install” button on the item ‘python-matplotlib’ to install it.

2) Use ‘apt-get’ in terminal.

Type the following line in terminal.

sudo apt-get install python-matplotlib

With either of the above methods, you will get matplotlib-0.99.1.1 installed on your machine. This version might be enough for some cases of plotting basic figures, but does not provide the full features of matplotlib. In case of using version 0.99, even some of the official samples fail to run, like: date_index_formatter.py, and fill_between_demo.py.

Note: if you are using Ubuntu with a higher version, say 10.10, matplotlib installed via “apt-get” may have a newer version and can provide full features claimed in the documentation.

8 responses to “Howto: Install matplotlib on Ubuntu 10.04.1”

  1. Jesus, this is the right article I have been looking for 3 months.
    GREAT THANKS, and that works.
    BTW: for unbuntu 10.10 Desktop distribution, you need install g++.
    that’s so weired that unbuntu offical dist doenst include g++

    1. Can you feel the difference between 10.10 and 10.04. I chose 10.04 because it has a suffix “LTS” which means “long term support” and makes it easier to keep the OS updated, I guess.

  2. prabhakar srinivasan Avatar
    prabhakar srinivasan

    Thanks! perfect article!

  3. Michael Haberler Avatar
    Michael Haberler

    There’s a dependency introduced in matplotlib commit cba27cd7

    (Christoph Gohlke 2011-09-20 19:26:54 -0700 521) cbook._putmask(xa, xa==1.0, np.nextafter(xa.dtype.type

    This requires a newer numpy version than 1.3 which comes with 10.04

    what works is:

    git clone git://github.com/matplotlib/matplotlib.git
    git checkout -b no-nextafter 05781473b63668c7efdbe1e3c69fe97ae9bf4aea
    cd matplotlib
    sudo python setup.py install

    1. Thanks for your input, Michael.

  4. whoah this blog is great i like reading your posts.

    Stay up the great work! You know, a lot of individuals are looking around for this information,
    you could aid them greatly.

  5. I was curious if you ever considered changing the structure
    of your website? Its very well written; I love what youve got to
    say. But maybe you could a little more in the way of content so people could connect with it better.
    Youve got an awful lot of text for only having 1 or two pictures.
    Maybe you could space it out better?

  6. […] As it turns out, the repository for Ubuntu 10.04 LTS has an obsolescent version of matplotlib and 3D examples from http://matplotlib.sourceforge.net will not even run. The solution is to install the current version of matplotlib following these instructions. […]

Leave a comment

  • Design a site like this with WordPress.com
    Get started