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.
Leave a comment