sympy python and graphics

28 views
Skip to first unread message

Alan Bromborsky

unread,
Nov 3, 2020, 10:52:01 AM11/3/20
to sympy

One thing I think is lacking in python is the ability to generate report quality graphics directly.  The best available is matplotlib which doesn't really do the job all the time.  I have a paper I wrote (for my own edification) using sympy and galagebra to solve the Foucault pendulum.  For graphics and drawings I used the Asymptote  software (scripted graphics).  Below is the code for the drawing of the coordinate system I used and the resulting drawing.  I am suggesting (the coding is beyond me) is a full featured python wrapper for Asymptote (a simple one does exist) graphics.  Would anyone be interested in doing this or do you only use interactive programs for figures (if so which programs)?

import three;
import math;
texpreamble("\usepackage{bm}");

size(500,0);

pen thickp=linewidth(0.5mm);
real radius=0.8, lambda=37, aux=60;

currentprojection=perspective(4,1,2);

// Planes
pen bg=gray(0.9)+opacity(0.5);
//draw(surface((1.2,0,0)--(1.2,0,1.2)--(0,0,1.2)--(0,0,0)--cycle),bg);
//draw(surface((0,1.2,0)--(0,1.2,1.2)--(0,0,1.2)--(0,0,0)--cycle),bg);
//draw(surface((1.2,0,0)--(1.2,1.2,0)--(0,1.2,0)--(0,0,0)--cycle),bg);

string lab_size;
lab_size = "\LARGE";
real r=0.9;
pen p=rgb(0,0.7,0);
draw(Label(lab_size+"$x$",1),O--r*X,p,Arrow3);
draw(Label(lab_size+"$y$",1),O--r*Y,p,Arrow3);
draw(Label(lab_size+"$z$",1),O--r*Z,p,Arrow3);

// Point Q
triple pQ=radius*dir(lambda,aux);
triple pQ_xy = radius*dir(90.0,aux);
triple pQ_x  = radius*dir(90.0,0.0);
draw(O--radius*dir(90,aux),dashed);

draw(lab_size+"$\theta$",arc(O,0.7pQ,0.7pQ_xy),N+0.3E,Arrows3);
draw(lab_size+"$\phi =\omega_{E}t$",arc(O,0.7pQ_xy,0.7pQ_x),Arrows3);


// Spherical octant
real r=sqrt(pQ.x^2+pQ.y^2);
draw(arc((0,0,pQ.z),(r,0,pQ.z),(0,r,pQ.z)),dashed);
draw(arc(O,radius*Z,radius*dir(90,aux)),dashed);
draw(arc(O,radius*Z,radius*X),thickp);
draw(arc(O,radius*Z,radius*Y),thickp);
draw(arc(O,radius*X,radius*Y),thickp);

// Moving axes
triple i=dir(90+lambda,aux);
triple k=unit(pQ);
triple j=cross(k,i);

draw(Label(lab_size+"$\bm{e}_{\theta}$",1),pQ--pQ+0.15*i,E,red,Arrow3);
draw(Label(lab_size+"$\bm{e}_{\phi}$",1),pQ--pQ+0.15*j,E,red,Arrow3);
draw(Label(lab_size+"$\bm{e}_{r}$",1),pQ--pQ+0.15*k,N,red,Arrow3);
draw(pQ+0.15k--1.45pQ,red+dashed);

draw(lab_size+"$\bm{r}$",1.45pQ--0.075*i+0.075j+pQ,1.5NE,red,Arrow3);
draw(Label(lab_size+"$u_{\phi}$",0.65),0.075*i+pQ--0.075*i+0.075j+pQ,blue,Arrow3);
draw(Label(lab_size+"$u_{\theta}$",0.75),0.075*j+pQ--0.075*i+0.075j+pQ,N,blue,Arrow3);

draw(Label(lab_size+"$\bm{R}_{E}$",0.8),O--pQ,W,Arrow3);
draw(lab_size+"$\omega_{E}$",arc(0.88Z,0.2,90,-120,90,160,CW),1.2N,Arrow3);
dot(lab_size+"$\rm Pivot$",1.45pQ,W,linewidth(5));



Aaron Meurer

unread,
Nov 3, 2020, 4:37:58 PM11/3/20
to sympy
If the graphics you are producing are based on data, I think matplotlib is your best option for producing publication quality figures, at least using Python. For the sort of figure you've created, I would also look at TikZ, which can produce similar quality images directly in LaTeX. Asymptote looks like it produces nice graphics and I agree a Python wrapper would be useful.

Aaron Meurer

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/faf83fe1-52c0-00c4-60d6-b79afa941916%40gmail.com.
Reply all
Reply to author
Forward
0 new messages