maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   MeeGo / Harmattan (https://talk.maemo.org/forumdisplay.php?f=45)
-   -   [Announce] MatPlotLib - 2D & 3D plots for MeeGo Harmattan (https://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.

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.1-3 Harmattan release (12/10/2014). MatPlotLib is visible in MeeGo Harmattan Application Manager and is installed easier using Warehouse;
- 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), 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
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 3.9 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 3.5 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.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 ("python-matplotlib" package).

Warehouse showing MatPlotLib 1.3.1 available to install :
http://www.robertocolistete.net/MatP...oHarmattan.png

The MatPlotLib v1.3.1 takes 26MB, while its dependencies (NumPy >= 1.7.0 and "python-dateutil", "python-pyparsing", "python-tornado", "python-tz", etc) take additionally 32 MB after automatic installation. "python-pyside" (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.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 #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 :
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 (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 "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.

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.

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 18:38.

vBulletin® Version 3.8.8