Active Topics

 


Reply
Thread Tools
Posts: 1,269 | Thanked: 3,961 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 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


3D surface plot of a function of two variables (takes 5.0 s) :
$ python surface3d_demo.py


2D vector field plot (takes 2.4 s):
$ python convfield.py


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") :

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 :

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.


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.
__________________
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 ---
Sailfish : Sony Xperia X, Gemini, Jolla, Jolla C, Jolla Tablet, Nexus 4. Nokia N9, N900, N810.

Last edited by rcolistete; 2014-10-28 at 16:59. Reason: Updated to MatPlotLib 1.4.2
 

The Following 12 Users Say Thank You to rcolistete For This Useful Post:
Posts: 1,269 | Thanked: 3,961 times | Joined on May 2011 @ Brazil
#2
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.


contourfxy.py : contour plot of two variables, f=f(x,y), saving to a (PNG) file. Takes 5.4s.


densityfxy.py : density shaded relief plot of two variables, f=f(x,y), saving to a (PNG) file. Takes 5.1s.


vectorfieldFxy.py : vector field plot in 2D, F=F(x,y), saving to a (PNG) file. Takes 4.3s.


surfacefxy.py : surface plot of two variables, f=f(x,y), saving to a (PNG) file. Takes 8.7s.


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.
__________________
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 ---
Sailfish : Sony Xperia X, Gemini, Jolla, Jolla C, Jolla Tablet, Nexus 4. Nokia N9, N900, N810.

Last edited by rcolistete; 2014-06-09 at 09:19.
 

The Following User Says Thank You to rcolistete For This Useful Post:
Posts: 1,269 | Thanked: 3,961 times | Joined on May 2011 @ Brazil
#3
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.
__________________
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 ---
Sailfish : Sony Xperia X, Gemini, Jolla, Jolla C, Jolla Tablet, Nexus 4. Nokia N9, N900, N810.
 

The Following 4 Users Say Thank You to rcolistete For This Useful Post:
Posts: 1,335 | Thanked: 3,931 times | Joined on Jul 2010 @ Brittany, France
#4
Thanks for that! I hope you'll port R to Sailfish too someday, can't wait to run/fiddle my scripts on the Jolla!
 

The Following User Says Thank You to Kabouik For This Useful Post:
Posts: 1,269 | Thanked: 3,961 times | Joined on May 2011 @ Brazil
#5
Originally Posted by Kabouik View Post
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).
__________________
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 ---
Sailfish : Sony Xperia X, Gemini, Jolla, Jolla C, Jolla Tablet, Nexus 4. Nokia N9, N900, N810.
 

The Following 2 Users Say Thank You to rcolistete For This Useful Post:
Posts: 1,335 | Thanked: 3,931 times | Joined on Jul 2010 @ Brittany, France
#6
Oh noes, don't tell me there's no hope. And the tohkbd2 is coming, I want R. :<

Last edited by Kabouik; 2014-09-22 at 23:57.
 

The Following User Says Thank You to Kabouik For This Useful Post:
Posts: 752 | Thanked: 2,808 times | Joined on Jan 2011 @ Czech Republic
#7
Originally Posted by rcolistete View Post
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?
 
Posts: 1,269 | Thanked: 3,961 times | Joined on May 2011 @ Brazil
#8
Moved the discussion about Fortran for Sailfish to a dedicated topic.
__________________
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 ---
Sailfish : Sony Xperia X, Gemini, Jolla, Jolla C, Jolla Tablet, Nexus 4. Nokia N9, N900, N810.

Last edited by rcolistete; 2014-09-25 at 15:31.
 
Posts: 1,269 | Thanked: 3,961 times | Joined on May 2011 @ Brazil
#9
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.
__________________
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 ---
Sailfish : Sony Xperia X, Gemini, Jolla, Jolla C, Jolla Tablet, Nexus 4. Nokia N9, N900, N810.
 

The Following User Says Thank You to rcolistete For This Useful Post:
Posts: 1,269 | Thanked: 3,961 times | Joined on May 2011 @ Brazil
#10
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.
__________________
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 ---
Sailfish : Sony Xperia X, Gemini, Jolla, Jolla C, Jolla Tablet, Nexus 4. Nokia N9, N900, N810.
 

The Following User Says Thank You to rcolistete For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 00:52.