maemo.org - Talk

maemo.org - Talk (http://talk.maemo.org/index.php)
-   MeeGo / Harmattan (http://talk.maemo.org/forumdisplay.php?f=45)
-   -   [Announce] MatPlotLib - 2D & 3D plots for MeeGo Harmattan (http://talk.maemo.org/showthread.php?t=80353)

rcolistete 2011-11-24 23:21

[Announce] MatPlotLib - 2D & 3D plots for MeeGo Harmattan
 
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 simple_plot.py
http://www.robertocolistete.net/matplotlib/figplot.png

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 :
http://www.robertocolistete.net/MatP...Qt4backend.png

3D surface plot of a function of two variables (takes 9.7 s) :
$ python surface3d_demo.py
http://www.robertocolistete.net/matp...figsurface.png

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 :
http://www.robertocolistete.net/MatP...Qt4backend.png

2D vector field plot (takes 4.6 s):
$ python convfield.py
http://www.robertocolistete.net/matp.../convfield.png

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 :
http://www.robertocolistete.net/matp...9_terminal.png
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 :
http://www.robertocolistete.net/matp...Qt4backend.png
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 :
http://www.robertocolistete.net/ipyt...-0.13.1_N9.png

Or IPython Qt console session :
http://www.robertocolistete.net/ipyt...-0.13.1_N9.png

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.

vielfrass 2011-11-25 06:26

Re: [Announce] MatPlotLib - 2D & 3D plots for MeeGo Harmattan
 
from pylab import *
does not work for me after your described procedure:
No module named pylab

rcolistete 2011-11-25 07:37

Re: [Announce] MatPlotLib - 2D & 3D plots for MeeGo Harmattan
 
Quote:

Originally Posted by vielfrass (Post 1128734)
from pylab import *
does not work for me after your described procedure:
No module named pylab

Please, give me the full error message.

Also check if, using Terminal :
$ apt-cache show python-matplotlib
shows a lot of information about the package (to confirm if it is installed).

rcolistete 2011-11-26 18:21

Re: [Announce] MatPlotLib - 2D & 3D plots for MeeGo Harmattan
 
Here are some useful examples/templates scripts for ploting with MatPlotLib/NumPy. They have many options to change : domain, function, labels, title, etc. To adapt them to your use, just open the .py file with a text editor (for example Nano for Nokia N9 in Nokia Store), change the definitions in the section "# Personalize your plot parameters here", save and run (using Terminal) :
$ python <scriptname>.py
Timings for MatPlotLib 1.2.0 and NumPy 1.4.1 on Nokia N9.

plotfx.py : Plot of one variable, f=f(x), saving to a (PNG) file. Takes 8.4 s on Nokia N9.
http://www.robertocolistete.net/MatPlotLib/plotfx.png

contourfxy.py : contour plot of two variables, f=f(x,y), saving to a (PNG) file. Takes 10.2 s on Nokia N9.
http://www.robertocolistete.net/MatP...contourfxy.png

densityfxy.py : density shaded relief plot of two variables, f=f(x,y), saving to a (PNG) file. Takes 10.3 s on Nokia N9.
http://www.robertocolistete.net/MatP...densityfxy.png

vectorfieldFxy.py : vector field plot in 2D, F=F(x,y), saving to a (PNG) file. Takes 8.2 s on Nokia N9.
http://www.robertocolistete.net/MatP.../vectorFxy.png

surfacefxy.py : surface plot of two variables, f=f(x,y), saving to a (PNG) file. Takes 16.6 s on Nokia N9.
http://www.robertocolistete.net/MatP...surfacefxy.png

vielfrass 2011-11-26 21:02

Re: [Announce] MatPlotLib - 2D & 3D plots for MeeGo Harmattan
 
Quote:

Originally Posted by rcolistete (Post 1128757)
$ apt-cache show python-matplotlib
shows a lot of information about the package (to confirm if it is installed).

Thanks for the hint. I'm a Python newbie. Seems to installed uncomplete. I'm doing the procedure again.
:rolleyes:

vielfrass 2011-11-26 21:24

Re: [Announce] MatPlotLib - 2D & 3D plots for MeeGo Harmattan
 
Quote:

Originally Posted by rcolistete (Post 1128757)
Please, give me the full error message.
$ apt-cache show python-matplotlib
shows a lot of information about the package (to confirm if it is installed).

:rolleyes: Actually reading the error message helps, some times...

This fixed it:
Code:

apt-get install python-central
Thanks a lot. This will help me learning Python and becoming more independent from MatLab.

vielfrass 2011-11-26 21:33

Re: [Announce] MatPlotLib - 2D & 3D plots for MeeGo Harmattan
 
Will it be possible to have the QT iPython console on the N9 some day?
http://ipython.org/ipython-doc/dev/i...qtconsole.html

rcolistete 2011-11-26 21:41

Re: [Announce] MatPlotLib - 2D & 3D plots for MeeGo Harmattan
 
Quote:

Originally Posted by vielfrass (Post 1129350)
:rolleyes: Actually reading the error message helps, some times...

This fixed it:
Code:

apt-get install python-central
Thanks a lot. This will help me learning Python and becoming more independent from MatLab.

It was my fault, 'python-central' was missing in the installation instructions above. It was already installed in my Nokia N9 (due to 'python-imaging') and I missed this detail...

The installation instructions are now fixed and complete.

Thank you very much.

rcolistete 2011-11-26 22:00

Re: [Announce] MatPlotLib - 2D & 3D plots for MeeGo Harmattan
 
Quote:

Originally Posted by vielfrass (Post 1129352)
Will it be possible to have the QT iPython console on the N9 some day?
http://ipython.org/ipython-doc/dev/i...qtconsole.html

I have answered your question in iPython for MeeGo Harmattan topic.

But my priority is to (try to) release MatPlotLib 1.1 with a possible Qt backend running on Nokia N9/N950.

blinkman04 2012-02-01 20:38

Re: [Announce] MatPlotLib - 2D & 3D plots for MeeGo Harmattan
 
Hello !

I had just a little problem when i try to install the Library...

When i enter this command : " # dpkg -i python-matplotlib-data_1.0.0-1_all.deb "

My N9 returning this error : "Aegis rejecting python-matplotlib-data_1.0.0-1_all.deb : Could not open debian archive
Aegis aborting dpkg -- all listed package files rejected


Sorry for my approxymatly english .. i'm french ^^


All times are GMT. The time now is 17:28.

vBulletin® Version 3.8.8