graphic conversion from maxima to sage

145 views
Skip to first unread message

HG

unread,
Mar 25, 2014, 4:50:38 AM3/25/14
to sage-s...@googlegroups.com


Hi,
I got this yin-yang from http://riotorto.users.sourceforge.net/gnuplot/func2d/index.html (thanks for it !) :

draw2d(
    proportional_axes = xy,
    title             = "Ying-Yang",
    ellipse(0,0,2,2,0,360),
    fill_color        = black,
    filled_func       = -sqrt(4-x^2),
    explicit(if x < 0 then sqrt(-x^2-2*x) else -sqrt(-x^2+2*x),x,-2,2) ) $


But I need it in sagemath to get it well embedd in texmacs.
After long trying I didn't not success, my main problem is conditions.
If a good soul could do it for me all my thanks.
Kind regards,
HG

I have done this which is not really good :
y=sqrt(4-x^2);b=y
r=sqrt(-x^2-2*x);q=-sqrt(-x^2+2*x)
e=solve(b==r,y)
c=plot(b,(y,-2,2),fill=True,fillcolor="black",color="black",figsize=3,aspect_ratio=1);
c+=plot(r,(y,-2,2),fill=True,fillcolor="red",color="red",figsize=3,aspect_ratio=1)
d=plot(-b,(y,-2,2),fill=True,fillcolor="red",color="red",figsize=3,aspect_ratio=1);
d+=plot(-r,(y,-2,2),fill=True,fillcolor="red",color="red",figsize=3,aspect_ratio=1);
p=plot(q,(y,-2,2),fill=True,fillcolor="red",color="red",figsize=3);
p+=plot(q,(y,-2,2),fill=True,fillcolor="black",color="red",figsize=3)
plot(c+d+p,figsize=2,aspect_ratio=1,axes=False)

kcrisman

unread,
Mar 25, 2014, 10:21:29 AM3/25/14
to sage-s...@googlegroups.com

But I need it in sagemath to get it well embedd in texmacs.
After long trying I didn't not success, my main problem is conditions.
If a good soul could do it for me all my thanks.
Kind regards,
HG

kcrisman

unread,
Mar 25, 2014, 10:28:45 AM3/25/14
to sage-s...@googlegroups.com
Okay, or http://sagecell.sagemath.org/?q=pwwdqz should help.  Personally, I don't like this parametrization; it doesn't seem to look right at the origin, not smooth enough. 

HG

unread,
Mar 25, 2014, 2:19:07 PM3/25/14
to sage-s...@googlegroups.com
Yes thanks but I tried I can't set conditions in the equation (I am not an expert at all !)
--
You received this message because you are subscribed to a topic in the Google Groups "sage-support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sage-support/s0uAGNAVWtw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sage-support...@googlegroups.com.
To post to this group, send email to sage-s...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

HG

unread,
Mar 25, 2014, 2:21:31 PM3/25/14
to sage-s...@googlegroups.com
Sorry I answer you too quickly and had not seen the link you send to me, which is exactly what I want !
Thanks for your help
Henri

Le 25/03/2014 15:28, kcrisman a écrit :

HG

unread,
Mar 25, 2014, 3:39:55 PM3/25/14
to sage-s...@googlegroups.com
Final and agreeing with you not enaugh smooth but it's ok for what I need. I can't use show() on texmacs because the it's an external windows.
Thanks again for your help :)
Henri

Sage]  def f(x):
    if x<0:
        return sqrt(-x^2-2*x)
    else:
        return -sqrt(-x^2+2*x)

Sage]  a=plot(f,(x,-2,2),color='black',fill=sqrt(4-x^2),fillcolor="black")

Sage]  b=plot(f,(x,-2,2),color='red',fill=-sqrt(4-x^2),fillcolor="red")

Sage]  plot(a+b,figsize=2,axes=False,aspect_ratio=1)





Le 25/03/2014 15:28, kcrisman a écrit :

HG

unread,
Apr 17, 2014, 6:32:31 AM4/17/14
to sage-s...@googlegroups.com

Hi,
I do a plot with **params which is quiete usefull to have it as a
compact style.
After googling a lot I was trying to see if one can do the same with
**legend ? or other keyword ?
I didn't find any answer, is it possible ?
it would be easier to put all in a command ?
regards
Henri

p=plot(sin(x*5), legend_label='sin',
legend_color='red',frame=True,figsize=3,fontsize=6);
p.set_legend_options(font_size=6);
p.set_legend_options(back_color=(0.9,0.9,0.9));
p.set_legend_options(loc=(1));
p.set_legend_options(shadow=True);
p.set_legend_options(borderaxespad=1);
p.set_legend_options(fancybox=False); p



kcrisman

unread,
Apr 17, 2014, 8:19:53 AM4/17/14
to sage-s...@googlegroups.com
Either of these options (see the documentation for p.show?):

sage: p=plot(sin(x*5), legend_label='sin', legend_color='red',frame=True,figsize=3,fontsize=6);
sage: p.set_legend_options(font_size=6,back_color=(.9,.9,.9),loc=(1),shadow=True, borderaxespad=1,fancybox=False) 

sage: p = plot(sin(x*5), legend_label=r'$\sin$', legend_color='red',frame=True,figsize=3,fontsize=6).show(legend_back_color=(.9,.9,.9),legend_loc=(1),legend_shadow=True,legend_fancybox=False)
 

Michael Orlitzky

unread,
Apr 17, 2014, 8:48:14 AM4/17/14
to sage-s...@googlegroups.com
On 04/17/2014 06:32 AM, HG wrote:
>
> Hi,
> I do a plot with **params which is quiete usefull to have it as a
> compact style.
> After googling a lot I was trying to see if one can do the same with
> **legend ? or other keyword ?
> I didn't find any answer, is it possible ?
> it would be easier to put all in a command ?

The same syntax should work:

legend_opts = { 'back_color': 'white', 'shadow': True }

p.set_legend_options(**legend_opts)


HG

unread,
Apr 18, 2014, 1:50:53 AM4/18/14
to sage-s...@googlegroups.com
I forget to say I can't use the show command because the plot is
external in a texmacs session,
this one should work I try it.
thanks
Henri

HG

unread,
Apr 18, 2014, 4:09:24 AM4/18/14
to sage-s...@googlegroups.com
It doesn't work ... It seems to be a matplotlib options which I can't
use inside texmacs directly.
Strange that **params works and not **legend.

Le 17/04/2014 14:48, Michael Orlitzky a écrit :

HG

unread,
Apr 19, 2014, 3:56:21 AM4/19/14
to sage-s...@googlegroups.com
Hi,
Sorry I mistaken : Your suggestion does work but apparently some
commands don't work.
I am trying further...
Thanks
Henri
Le 17/04/2014 14:48, Michael Orlitzky a écrit :

Emmanuel Charpentier

unread,
Apr 22, 2014, 4:24:42 PM4/22/14
to sage-s...@googlegroups.com
Apart for being a mouthful of a one-liner, what would be wrong with :
plot(sqrt(-x^2+2*abs(x))*sgn(-x),[x,-2,2] ,figsize=4,
      xmin=-2,  xmax=2, ymin=-2, ymax=2, aspect_ratio=1, axes=False,
      fill=-sqrt(4-x^2), color="black", fillcolor="black", fillalpha=1) +
plot(sqrt(-x^2+2*abs(x))*sgn(-x),[x,-2,2], figsize=4
             xmin=-2, xmax=2, ymin=-2, ymax=2, aspect_ratio=1, axes=False,
             fill=sqrt(4-x^2), color="red", fillcolor="red", fillalpha=1)
, pray tell me ?

Aand you don't have the to put up with the black border up the positive half circle that the draw2d solution plots. An implicit plot might be a better way to render this, BTW, but I dont' have it on the tips of my fingers right now....

Note : the "figsize=4" bit is for emacs' sage_mode sake. It looks nice'n smooth without it.

Since it's pure sage, it could be rendered even better in tikz ... if I could find a way to coax matplot to use its built-in interface to tikz. But the damn thing is quite opaque to me. Any idea ?

[ BTW : this (rendering via tikz) might be a nice enhancement for sagetex users... Hmmm... I'll have to dive in the source code. Not for now, alas... ]

HTH,
--
Emmanuel Charpentier

HG

unread,
Apr 23, 2014, 5:31:30 AM4/23/14
to sage-s...@googlegroups.com
It's perfect ! I prefer an one line command in texmacs !
Thanks
Henri

Henri Girard

unread,
Feb 7, 2016, 8:25:57 AM2/7/16
to sage-s...@googlegroups.com
Hi,
I finally got this with circuitikz (tikz), in a jupyter sage-n=ipython (sage-7.1 beta2 of today fresh compile, but I can work on other version too) :
%matplotlib inline
#%display latex
%install_ext http://raw.github.com/jrjohansson/ipython-circuitikz/master/circuitikz.py
%load_ext circuitikz
%%circuitikz filename=geo dpi=125
\begin{circuitikz}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\draw[->,color=black] (-5.98,0.) -- (5.36,0.);
\foreach \x in {-5.,-4.,-3.,-2.,-1.,1.,2.,3.,4.,5.}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[->,color=black] (0.,-4.08) -- (0.,4.78);
\foreach \y in {-4.,-3.,-2.,-1.,1.,2.,3.,4.}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
\clip(-5.98,-4.08) rectangle (5.36,4.78);
\draw(0.,0.) circle (3.cm);
\end{circuitikz}

It's a circle I draw in geogebra, I exported it to pdf/tikz from gg export and after I copy it in sage ipython notebook.
Kind regards

Henri

Le 22/04/2014 22:24, Emmanuel Charpentier a écrit :
--

Henri Girard

unread,
Feb 7, 2016, 8:53:39 AM2/7/16
to sage-s...@googlegroups.com
I forgot would tikz or circuitikz work on sagemathcloud ? Is it installed ?


Le 07/02/2016 14:23, Henri Girard a écrit :
Hi,
I finally got this with circuitikz (tikz), in a jupyter sage-n=ipython (sage-7.1 beta2 of today fresh compile, but I can work on other version too) :
%matplotlib inline
#%display latex
%install_ext http://raw.github.com/jrjohansson/ipython-circuitikz/master/circuitikz.py
%load_ext circuitikz
%%circuitikz filename=geo dpi=125
\begin{circuitikz}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\draw[->,color=black] (-5.98,0.) -- (5.36,0.);
\foreach \x in {-5.,-4.,-3.,-2.,-1.,1.,2.,3.,4.,5.}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[->,color=black] (0.,-4.08) -- (0.,4.78);
\foreach \y in {-4.,-3.,-2.,-1.,1.,2.,3.,4.}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
\clip(-5.98,-4.08) rectangle (5.36,4.78);
\draw(0.,0.) circle (3.cm);
\end{circuitikz}


Le 22/04/2014 22:24, Emmanuel Charpentier a écrit :
--

HG

unread,
Feb 16, 2016, 12:46:01 PM2/16/16
to sage-support
At the moment I couldn't use circuitikz/tiks on SMC, but on local installation it works fine in sagemath ipython notebook sage-7 (probably sage-6.10 too... I haven't tried).
William could you install tikz and circuitikz on SMC or tell us how to do it ?
Best regards
Henri
(I am quiet buzy trying to use vpython on sage, it works on jupyter notebook)


Le mardi 25 mars 2014 09:50:38 UTC+1, HG a écrit :

Harald Schilly

unread,
Feb 18, 2016, 6:29:10 AM2/18/16
to sage-support


On Sunday, February 7, 2016 at 2:53:39 PM UTC+1, HG wrote:
I forgot would tikz or circuitikz work on sagemathcloud ? Is it installed ?

Hi, you have to write to our mailing lists or directly to he...@sagemath.com if you have a question like that. It only came to my attention, thank's to Samuel, that you  were asking here.

All of this is installed via the package "texlive-pictures". Besides that, I fear I've no clear picture what you actually want to do -- or maybe I've overlooked a message here?

Best wishes,
Harald


Reply all
Reply to author
Forward
0 new messages