View Single Post
Posts: 924 | Thanked: 2,160 times | Joined on May 2011 @ Brazil
MatPlotLib is a Python library for making 2D and 3D plots, usually using NumPy to calculate the data. See the MatPlotLib gallery to have an idea of which plots can be make using a Nokia N9/N950.

There are 2 versions to choose to install on MeeGo Harmattan :
- new MatPlotLib 1.2.1 (26/03/2013), released for MeeGo Harmattan in 05/06/2013, available in my Harmattan repository;
- MatPlotLib 1.0.0 (06/07/2010), released on MeeGo Harmattan in 24/11/2011, available in my Harmattan repository for manual download.

MatPlotLib 1.2.1 x 1.0.0 packages on MeeGo Harmattan:
- v1.2.1 is newer (26/03/2013) than v1.0.0 (06/07/2010);
- v1.2.x has a graphical backend (Qt4App/PySide) to interactively show plots;
- automatic configuration in v1.2.x, so no need to create directories and matplotlibrc file like in v1.0.0;
- v1.2.x is based on upstream and Ubuntu 13.04 versions, while v1.0.0 is based on the Maemo 5 version of Simon Pickering;
- many new features, see the "MatPlotLib What's New" : animation, new types of plots, many improvements in 3D plots, etc.

Version history :
- MatPlotLib 1.2.1-2 Harmattan release (15/06/2013);
- MatPlotLib 1.2.1-1 (26/03/2013) released for MeeGo Harmattan (06/06/2013);
- MatPlotLib 1.2.0-2 Harmattan release (12/02/2013);
- MatPlotLib 1.2.0-1 (08/01/2013) released for MeeGo Harmattan (09/02/2013).

For MatPlotLib on Sailfish/Mer, see the topic "MatPlotLib - 2D & 3D plots for Sailfish".

Examples and screenshots of MatPlotLib on MeeGo Harmattan

Some graphics produced by using MatPlotLib 1.2 with NumPy 1.4.1 on a Nokia N9. See more examples in post #4. Download the .py (Python) script and using Terminal type in the the same directory the commands after the "$" :

2D plot of a function (sin) of one variable (takes 4.4 s).
$ python

Qt4/PySide backend showing a plot of one variable, f=f(x), of a damped harmonic oscillator, see script in post #4, where the "savefig" command was commented and "show()" was uncommented :

3D surface plot of a function of two variables (takes 9.7 s) :
$ python

The same above, shown by the Qt4/PySide backend using "" instead of "plt.savefig" in the script, allows to touch to rotate the 3D plot :

2D vector field plot (takes 4.6 s):
$ python

Installing MatPlotLib on MeeGo Harmattan

See post #33 if you want to install MatPlotLib 1.0.0. The instructions below are for MatPlotLib 1.2.1.

After configuring my Harmattan repository, open the Terminal, type :
$ devel-su
and the 'rootme' password, then
# apt-get update
# apt-get install python-matplotlib
confirming the installation. The MatPlotLib packages and dependencies (1.7.x) take almost 50 MB after install.

To remove any conflicting configuration of MatPlotLib 1.0.0 (previous versions), type in Terminal as user :
$ cd ~
$ rm -rf .matplotlib

The Qt4/PySide graphical backend assumes PySide is installed (which is used by many MeeGo Harmattan softwares). If you want Qt4/PySide backend and PySide is not installed, it is simple to install it, just type in Terminal as root :
# apt-get install python-pyside
If you don't want to use an interactive graphical backend (i.e., Qt4/PySide) by default, then as user in Terminal, type :
$ cd ~
$ mkdir .matplotlib
$ echo 'backend : Agg' > .matplotlib/matplotlibrc
so the Agg backend becomes the default one. With non interactive backend, the plots are not shown in the screen and can only be saved to files (by using "savefig" command).

Using MatPlotLib on MeeGo Harmattan

It is strongly suggested to also install IPython for MeeGo Harmattan, so the interactive use of MatPlotLib/NumPy becomes a lot easier
With the new IPython 0.13.1-2 Harmattan, there are 3 interfaces : IPython terminal, IPython Notebook and IPython Qt console.

As a simple example (just type the text after the "In [n]:" lines) in IPython terminal :

In [1]: from pylab import *
In [2]: x = randn(10000); hist(x, 100)
In [3]: savefig('histogram.png')
In [4]: show()
The 1st line loads NumPy and MatPlotLib by using PyLab. The 2nd line calculates 10 thousand random numbers using NumPy, and makes a histogram (not shown in the screen). The 3rd line saves the histogram to a PNG file 'histogram.png' in the current directory (it could be a PDF figure, just use '.pdf' extension). Yeah, your Nokia N9 can easily create PDF files of plots ! The 4th line shows the plot in the interactive Qt4/PySide default backend of MatPlotLib 1.2, see below :

The interactive Qt4/PySide default backend is not touch friendly (as there is no mouse and the N9/N950 screen is small compared to a desktop PC), so only some features are practical to use. But it shows the plot in full screen since MatPlotLib 1.2 Harmattan (12/02/20130 allows to rotate 3D plots, etc.

To run IPython with PyLab (NumPy + MatPlotLib) in interactive mode in Terminal, there are many options :
- tap the IPython icon (v0.13.1), then type "%pylab";
- open the Terminal, type "ipython", then type "%pylab";
- open the Terminal, type "ipython --pylab".

See post #32 for time measurements of MatPlotLib 1.2.0 x 1.0.0 with NumPy 1.4.1 and 1.7.0.

IPython Notebook and IPython Qt console also support inline plots, just type "%pylab inline" inside the IPython Notebook session :

Or IPython Qt console session :

Documentation and Examples for MatPlotLib

MatPlotLib documentation is online in the official MatPlotLib site, in PDF format (16MB and more than 1,2 thousand pages), or help available in interactive mode by typing :
- "help(matplotlib)", after an "import matplotlib";
- "help(pylab)" or "help(pylab.matplotlib)", when using PyLab.

The package "python-matplotlib-doc_*.deb" only contains examples, but anyway it is purged as everything is in "/usr/share/doc/".

There is more than one hundred source code examples (.py Python files) in :
MatPlotLib gallery
MatPlotLib screenshots
MatPlotLib examples list
which can run on Nokia N9/N950.

For making plots with calculations using derivatives, integrals, etc, then SymPy is also available for MeeGo Harmattan :
SymPy (Computer Algebra System) for Maemo 4 & 5 & 6

By the way, be a N9/N950 proud user : MatPlotLib 1.2 is only available for Linux, Windows, Mac OS and now MeeGo 1.2 Harmattan.

Next steps for MatPlotLib on MeeGo Harmattan :
- (DONE, see this post and post #4) show easy script examples (with documentation) to make the most useful plots;
- (DONE, see my Harmattan repository) release MatPlotLib packages in a public MeeGo Harmattan repository (App);
- (DONE, now with MatPlotLib 1.2.0 there is a interactive backend on Nokia N9/N950) try to release MatPlotLib 1.1 or 1.2, which includes animations, PySide compatibility (so, maybe, I say, maybe, interactive backend could run on Nokia N9/950);
- (DONE, see MatPlotLib 1.2.0 Harmattan2) try to show Qt4/PySide backend in full screen;
- release softwares depending on MatPlotLib/Numpy with easy to use interface (in Qt Quick) to make from simple to complex plots of functions of 1 or 2 variables, of experimental data with error bars, eletrical vector field/potential, etc.
Python, C/C++, Qt and CAS developer. For Maemo/MeeGo/Sailfish :
Integral, Derivative, Limit - calculating mathematical integrals, derivatives and limits. SymPy - Computer Algebra System.
MatPlotLib - 2D & 3D plots in Python. IPython - Python interactive shell.
-- My blog about mobile & scientific computing ---
2 Nokia N9 16GB Black @ 1.35 GHz, 1 with Sailfish, Stowaway foldable BT keyboard.
Nexus 4 with Sailfish. Nokia N900 @ 1.1 GHz. N810. Nokia 9500. Psion Revo+.

Last edited by rcolistete; 06-17-2014 at 02:00 PM. Reason: Cited MatPlotLib 1.3.1 for Sailfish

The Following 16 Users Say Thank You to rcolistete For This Useful Post: