maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   SailfishOS (https://talk.maemo.org/forumdisplay.php?f=52)
-   -   [Announce] MatPlotLib 1.4.2 - 2D & 3D plots for Sailfish (https://talk.maemo.org/showthread.php?t=93307)

rcolistete 2014-06-09 07:15

[Announce] MatPlotLib 1.4.2 - 2D & 3D plots for Sailfish
 
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 made using Sailfish OS.

MatPlotLib version history on Sailfish :
- v1.4.2 (26/10/2014) released for Sailfish (27/10/2014);
- v1.4.1 (18/10/2014) released for Sailfish (19/10/2014);
- v1.4.0 (26/08/2014) released for Sailfish (15/09/2014);
- v1.3.1 (10/10/2013) released for Sailfish (08/06/2014).
All releases above have Agg and WebAgg backends.

For MatPlotLib on MeeGo Harmattan, see the topic "MatPlotLib - 2D & 3D plots for MeeGo Harmattan".

Examples and screenshots of MatPlotLib on Sailfish

Some graphics produced by using MatPlotLib 1.3.1 with NumPy 1.8.1 on a Nexus 4 running Sailfish. See more examples in post #2. 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 2.3 s).
$ python simple_plot.py
http://www.robertocolistete.net/MatPlotLib/figplot.png

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

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

Installing MatPlotLib on Sailfish

Install Warehouse (OpenRepos.net client) for Sailfish OS, see the Jolla Tides guide with screenshots.
Then open Warehouse, search for "MatPlotLib", enable the repository, then install it.

MatPlotLib v1.4.2 for Sailfish OS depends on NumPy, python-pyparsing, python-pytz, python-dateutil, python-six and python-tornado, so they will be installed, everything taking approx. 45 MB of space after installation.

The default backend (where the figure is displayed) is Agg, a non interactive backend, so 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, 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 ~/.config
$ mkdir matplotlib
$ echo 'backend : WebAgg' > matplotlib/matplotlibrc

Using MatPlotLib on Sailfish

It is strongly suggested to also install IPython for Sailfish, so the interactive use of MatPlotLib/NumPy becomes a lot easier.
With IPython 2.3.0 for Sailfish there are 2 interfaces : IPython terminal and IPython Notebook.


As a simple example (just type the text after the "In [n]:" lines) in IPython terminal (open Terminal, type "cd" to go to "/home/nemo/" folder, then type "ipython") :
http://www.robertocolistete.net/MatP...h_terminal.jpg
In [1]: from pylab import *
In [2]: x = randn(10000); hist(x, 100)
In [3]: savefig('histogram.png')
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 Sailfish smartphone can easily create PDF files of plots !

The same histogram above, but using "WebAgg" backend selected during the Python session :
http://www.robertocolistete.net/MatP...eb-backend.jpg
In [1]: import matplotlib
In [2]: matplotlib.use('webagg')
In [3]: import matplotlib.pyplot as plt
In [4]: import numpy as np
In [5]: plt.hist(np.random.randn(10000),100)
In [6]: plt.show()
The backend cannot be changed after pylab or matplotlib.pyplot is loaded. One workaround is to use "matplotlib = reload(matplotlib)" before changing the backend.

To run IPython with PyLab (NumPy + MatPlotLib) in interactive mode in Terminal, there are many options, open the Terminal, then type :
- "ipython --matplotlib", then type "from pylab import *";
- "ipython", then type "%matplotlib", then "from pylab import *";
- "ipython --matplotlib", then type "import matplotlib.pyplot as plt", then "import numpy as np";
- "ipython", then type "%matplotlib", then "import matplotlib.pyplot as plt", then "import numpy as np";
- "ipython", then type "%pylab";
- "ipython -pylab" (deprecated form).

Time to load MatPlotLib 1.4.2 on Nexus 4 running Sailfish :
- 0.6s via "from matplotlib import *" ;
- 2.5s (with NumPy 1.9.0) via "import pylab" or "from pylab import *".
Compare with the Nokia N9 timings.

IPython Notebook also supports inline plots, just type "%pylab inline" (or "%matplotlib", then "import matplotlib.pyplot as plt", then "import numpy as np") inside the IPython Notebook session.
http://www.robertocolistete.net/ipyt...SailfishOS.jpg

Documentation and Examples for MatPlotLib

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

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

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

By the way, be a Sailfish proud user : MatPlotLib 1.2.x/1.4.x is only available for Linux, Windows, Mac OS, iOS, MeeGo Harmattan and Sailfish.

rcolistete 2014-06-09 07:24

Re: [Announce] MatPlotLib 1.3.1 - 2D & 3D plots for Sailfish
 
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, change the definitions in the section "# Personalize your plot parameters here", save and run (using Terminal) :
$ python <scriptname>.py
Timings for MatPlotLib 1.3.1 and NumPy 1.8.1 on Nexus 4 running Sailfish.

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

contourfxy.py : contour plot of two variables, f=f(x,y), saving to a (PNG) file. Takes 5.4s.
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 5.1s.
http://www.robertocolistete.net/MatP...densityfxy.png

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

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

Comparing with the Nokia N9 results (with MatPlotLib 1.2.0 and NumPy 1.4.1 and other versions of MatPlotLib and NumPy), Sailfish on Jolla or Nexus 4 is approx. twice or more faster.

rcolistete 2014-09-16 23:56

Re: [Announce] MatPlotLib 1.4.0 - 2D & 3D plots for Sailfish
 
MatPlotLib 1.4.0 (26/08/2014) version now released (15/09/2014) for Sailfish OS. Some highlights :
- style module : experimental package to make managing the style of matplotlib figures easier;
- nbagg : interactive figures in ipython notebooks backed by the AGG renderer;
- violin plots and 3D quiver plots (projects done for a course at University of Toronto, Scarborough);
- new box plot interface (as bxp).
To install and use MatPlotLib 1.4.0 on Sailfish OS, see the 1st post.

Kabouik 2014-09-20 19:06

Re: [Announce] MatPlotLib 1.4.0 - 2D & 3D plots for Sailfish
 
Thanks for that! I hope you'll port R to Sailfish too someday, can't wait to run/fiddle my scripts on the Jolla!

rcolistete 2014-09-22 21:52

Re: [Announce] MatPlotLib 1.4.0 - 2D & 3D plots for Sailfish
 
Quote:

Originally Posted by Kabouik (Post 1439868)
Thanks for that! I hope you'll port R to Sailfish too someday, can't wait to run/fiddle my scripts on the Jolla!

I've tried to package R-base(-devel) .rpm package, but it seems to need Fortran compiler, which is not available on Mer/Sailfish.

Fortran is optional dependency for some packages (NumPy), and obligatory for others (SciPy, etc).

Kabouik 2014-09-22 22:19

Re: [Announce] MatPlotLib 1.4.0 - 2D & 3D plots for Sailfish
 
Oh noes, don't tell me there's no hope. :( And the tohkbd2 is coming, I want R. :<

nodevel 2014-09-25 09:46

Re: [Announce] MatPlotLib 1.4.0 - 2D & 3D plots for Sailfish
 
Quote:

Originally Posted by rcolistete (Post 1440078)
I've tried to package R-base(-devel) .rpm package, but it seems to need Fortran compiler, which is not available on Mer/Sailfish.

Fortran is optional dependency for some packages (NumPy), and obligatory for others (SciPy, etc).

That's the problem I ran into as well, when trying to package R-base. I'd love to see SciPy too, so it's a bit of a bummer.

I don't know much about Fortran, though. Is it solvable by simply packaging gcc-fortran or does gcc need to be rebuilt altogether?

rcolistete 2014-09-25 15:03

Re: [Announce] MatPlotLib 1.4.0 - 2D & 3D plots for Sailfish
 
Moved the discussion about Fortran for Sailfish to a dedicated topic.

rcolistete 2014-10-19 23:27

Re: [Announce] MatPlotLib 1.4.1 - 2D & 3D plots for Sailfish
 
MatPlotLib 1.4.1 (18/10/2014) version now released (19/10/2014) for Sailfish OS. It is bug fix release for MatPlotLib 1.4.x.
To install and use MatPlotLib 1.4.1 on Sailfish OS, see the 1st post.

rcolistete 2014-10-28 17:02

Re: [Announce] MatPlotLib 1.4.2 - 2D & 3D plots for Sailfish
 
MatPlotLib 1.4.2 (26/10/2014) version now released (27/10/2014) for Sailfish OS. It is another bug fix release for MatPlotLib 1.4.x.
To install and use MatPlotLib 1.4.2 on Sailfish OS, see the 1st post.


All times are GMT. The time now is 18:26.

vBulletin® Version 3.8.8