View Single Post
Posts: 1,269 | Thanked: 3,961 times | Joined on May 2011 @ Brazil
#32
The 2nd option to plot using SymPy 0.7.1/0.7.3, and the 3rd option to plot inside SymPy 0.7.2 is the use of mpmath plotting functions, which depend on MatPlotLib, so only available on Maemo 5 and MeeGo Harmattan.

Here are some examples of using the mpmath plotting functions, repeating some plots from post #11 (where another option to make plots in SymPy, "Plot()"/PyGlet, was used).

Observations about mpmath plots and MatPlotLib :
- mpmath plotting has no 2D parametric plots and no options to specify axis names, title name, plot color, etc;
- "import sympy.mpmath" is used instead of "from sympy.mpmath import *" to avoid conflict with the new "plot()" function (from plotting module);
- on Maemo 5, there is the warning message :
"/usr/lib/python2.5/site-packages/matplotlib/font_manager.py:1242: UserWarning: findfont: Font family ['sans-serif'] not found. Falling back to Bitstream Vera Sans"
and some symbols ('-' in axis numbers, etc) are not shown.
- on Maemo 5 and MeeGo Harmattan, mpmath plot functions without the option "file=<filename>" opens the interactive backend of MatPlotLib on your Nokia N900/N9/N950;
- on Maemo 5, the surface plots have some faulty colors, due MatPlotLib v1.00 being old;
- on MeeGo Harmattan, use MatPlotLib 1.2.0 so all the features cited here will work.

The 1st time is measured (with "%time") after loading "isympy", the 2nd time is for repeating plottings. Time is measured on Nokia N9 @ 1 GHz (with MatPlotLib 1.2.0 & NumPy 1.7.0) and Nokia N900 @ 600 Mhz (with MatPlotLib 1.0.0 & NumPy 1.4.0), both using SymPy 0.7.2.

2D Plot of a function of 1 variable, y = f(x), a dumped harmonic oscillator :
In [1]: import sympy.mpmath
In [2]: mpmath.plot(lambda x: 2.5*exp(-1.0*x/2)*cos(mpmath.pi*x), [0,10], file="oscillator.png")
Timing : Nokia N9 (4.8s/2.5s), N900 (8.9s/3.6s)


2D Density plot of complex function of z = re + j*im, here the zeta function :
In [1]: import sympy.mpmath
In [2]: mpmath.cplot(mpmath.zeta, re=[-7, 2], im=[-5, 5], file="zeta.png")
Timing : Nokia N9 (45s/44s), N900 (92s/88s)


3D surface in cartesian coordinates of 2 variables, z = f(x,y), it is by default z colored :
In [1]: import sympy.mpmath
In [2]: mpmath.splot(lambda x, y: 5*x*y*exp(-x**2-y**2), [-2,2], [-2,2], file="surface3D.png")
Timing : Nokia N9 (21s/15s), N900 (47s/36s).


3D parametric surface of 2 variables, x = f(u,v), y = g(u,v), z = h(u,v), here a moebius strip :
In [1]: import sympy.mpmath
In [2]: mpmath.splot(lambda u, v: [(2+(v/2)*cos(u/2))*cos(u), (2+(v/2)*cos(u/2))*sin(u), (v/2)*sin(u/2)], u=[0,2*mpmath.pi], v=[-1,1], file="moebius-strip.png")
Timing : Nokia N9 (22s/20s), N900 (51s/47s).
__________________
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; 2013-08-08 at 00:56. Reason: Added figures
 

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