Thread
:
[Announce] MatPlotLib  2D & 3D plots for MeeGo Harmattan
View Single Post
rcolistete
20111124 , 23:21
Posts: 1,131  Thanked: 3,009 times  Joined on May 2011 @ Brazil
#
1
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.
Release history for MeeGo 1.2 Harmattan (see the version history
"MatPlotLib What's New"
) :

MatPlotLib 1.3.1 (10/10/2013) first release for MeeGo 1.2 Harmattan (20/10/2014)
. New WebAgg backend (from a web browser) and many new features;

MatPlotLib 1.2.13 Harmattan release (12/10/2014)
. MatPlotLib is visible in MeeGo Harmattan Application Manager and is installed easier using Warehouse;

MatPlotLib 1.2.12 Harmattan release (15/06/2013)
;

MatPlotLib 1.2.11 (26/03/2013) released for MeeGo Harmattan (06/06/2013)
;

MatPlotLib 1.2.02 Harmattan release (12/02/2013)
;

MatPlotLib 1.2.01 (08/01/2013) released for MeeGo Harmattan (09/02/2013)
, with graphical backend (Qt4App/PySide) to interactively show plots.
It also has animations and many more features
;

MatPlotLib 1.0.0 (06/07/2010)
, released for MeeGo Harmattan in 24/11/2011, based on the
Maemo 5 version of Simon Pickering
.
Manual installation and configuration
, with only Agg backend.
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.3.1 with NumPy 1.9.0 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 3.3 s).
$ python
simple_plot.py
Qt4/PySide backend showing a plot of one variable, f=f(x), of a damped harmonic oscillator, see
plotfx.py script
in
post #4
, where the "savefig" command was commented and "show()" was uncommented :
3D surface plot of a function of two variables (takes 3.9 s) :
$ python
surface3d_demo.py
The same above, shown by
the Qt4/PySide backend
using "plt.show()" instead of "plt.savefig" in the script,
allows to touch to rotate the 3D plot
:
2D vector field plot (takes 3.5 s):
$ python
convfield.py
Installing MatPlotLib on MeeGo Harmattan
See
post #33
if you want to install MatPlotLib 1.0.0. The instructions below are for MatPlotLib 1.3.1.
MatPlotLib has 2 repositories options, so it can be :
 easily installed by using Warehouse / OpenRepos.net. Install
Warehouse
(
OpenRepos.net
client) for MeeGo Harmattan, then open Warehouse, search for "
MatPlotLib
", enable the repository and install;
 installed by using
my Harmattan repository
("pythonmatplotlib" package).
Warehouse showing MatPlotLib 1.3.1 available to install :
The MatPlotLib v1.3.1 takes 26MB, while its dependencies (
NumPy >= 1.7.0
and "pythondateutil", "pythonpyparsing", "pythontornado", "pythontz", etc) take additionally 32 MB after automatic installation. "pythonpyside" (if not installed by many MeeGo Harmattan other softwares), will be installed, taking >= 16MB.
MatPlotLib >= 1.3.x doesn't use '~/.matplotlib" configuration folder, but instead '~/.config/matplotlib". So upgrading from MatPlotLib < 1.3 to >= 1.3, then remove the older folder. Or, to remove any conflicting configuration of MatPlotLib 1.0.0 (previous versions), type in Terminal as user :
$ cd ~
$ rm rf .matplotlib
The default backend is Qt4/PySide interactive graphical backend. If you don't want to use an interactive graphical backend by default, then as user in Terminal, type :
$ cd ~
$ mkdir .config/matplotlib
$ echo 'backend : Agg' > .config/matplotlib/matplotlibrc
so the Agg non interactive backend becomes the default one. With non interactive backend, the plots are not shown in the screen and can only be saved to PNG, PDF, PS and SVG files (by using "savefig" command).
The
WebAgg backend
is also available on MatPlotLib >= 1.3, so the figures are displayed in a web browser with the URL
http://127.0.0.1:8988/
, it is interactive and suppport
MatPlotLib animations
. If you want to use the WebAgg backend by default, then in Terminal, type :
$ cd ~
$ mkdir .config/matplotlib
$ echo 'backend : WebAgg' > .config/matplotlib/matplotlibrc
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.12 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 #42 for time measurements
of MatPlotLib 1.3 x 1.2 x 1.0 with NumPy 1.7 and 1.9. Or older
post #32 for time measurements
of MatPlotLib 1.2 x 1.0 with NumPy 1.4 and 1.7.
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 (63MB and more than 2,6 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 "pythonmatplotlibdoc_*.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.
MatPlotLib is often used together with NumPy (for numerical calculations in Python), so see
topic about NumPy for MeeGo Harmattan
.
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, iOS, Sailfish and 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 MatPlotLib 1.4.x;
 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 for MeeGo Harmattan
More Python packages are listed in the
Python Harmattan Wiki
. See also
OpenRepos.net
.
__________________
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

Jolla. 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; 20141102 at
19:02
. Reason: Updated to MatPlotLib 1.3.1
Quote & Reply

The Following 17 Users Say Thank You to rcolistete For This Useful Post:
aRTee
,
death_jax
,
et3rnal
,
hrbani
,
HtheB
,
Joseph9560
,
khan.orak
,
Kozzi
,
lolloo
,
lorenzo
,
mscion
,
OVK
,
Ponyta
,
StefanL
,
strange1712
,
vielfrass
,
Wikiwide
rcolistete
View Public Profile
Send a private message to rcolistete
Visit rcolistete's homepage!
Find all posts by rcolistete