Thread
:
[Announce] MatPlotLib 1.4.2 - 2D & 3D plots for Sailfish
View Single Post
rcolistete
2014-06-09 , 07:15
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
Quote & Reply
|
The Following 12 Users Say Thank You to rcolistete For This Useful Post:
HolgerN
,
Jordi
,
juiceme
,
kureyon
,
max_power
,
mick3_de
,
minimos
,
mrsellout
,
nodevel
,
sponka
,
ste-phan
,
willi6868
rcolistete
View Public Profile
Send a private message to rcolistete
Visit rcolistete's homepage!
Find all posts by rcolistete