#12326: Add example(s) to documentation of combining Sage with matplotlib
---------------------------+------------------------------------------------
   Reporter:  kcrisman     |          Owner:  jason, was                      
       Type:  enhancement  |         Status:  new                             
   Priority:  minor        |      Milestone:  sage-5.0                        
  Component:  graphics     |       Keywords:  matplotlib graphics sage combine
Work_issues:               |       Upstream:  N/A                             
   Reviewer:               |         Author:                                  
     Merged:               |   Dependencies:                                  
---------------------------+------------------------------------------------
Description changed by kcrisman:

Old description:

> From [http://ask.sagemath.org/question/703/combine-sage-plot-with-
> matplotlib?answer=1734#1734 this ask.sagemath.org answer], an interesting
> sort of example (maybe could be spruced a little) which could be useful
> in the documentation for plotting.
> {{{
> #make some graphs
> x=var('x')
> g=plot(sin(x))
> g_ins=plot(cos(x))
> # plot main figure
> from matplotlib.figure import Figure
> figure = Figure()
> main_plot = figure.add_axes((0.2,0.2,0.7,0.7))
> g.matplotlib('a.svg', figure=figure, sub=main_plot)
> # plot an inset
> inset = figure.add_axes((0.6,0.2,0.3,0.3))
> g_ins.matplotlib('a.svg', figure=figure, sub=inset)
> # display graph (note that only single sage Graphics object has to be
> saved )
> g_ins.save('a.svg', figure=figure, sub=inset)
> }}}
> The user says
> >For some time, I was looking for a way how to generate several sage
> Graphics() objects
> >and plot them on a matplotlib canvas in an arbitrary arrangement, using
> .matplotlib()
> >function. It went out not being straightforward. I decided that the
> solution I've found
> >may be interesting for others as well.

New description:

 From [http://ask.sagemath.org/question/703/combine-sage-plot-with-
 matplotlib?answer=1734#1734 this ask.sagemath.org answer], an interesting
 sort of example (maybe could be spruced a little) which could be useful in
 the documentation for plotting.
 {{{
 #make some graphs
 x=var('x')
 g=plot(sin(x))
 g_ins=plot(cos(x))
 # plot main figure
 from matplotlib.figure import Figure
 figure = Figure()
 main_plot = figure.add_axes((0.2,0.2,0.7,0.7))
 g.matplotlib('a.svg', figure=figure, sub=main_plot)
 # plot an inset
 inset = figure.add_axes((0.6,0.2,0.3,0.3))
 g_ins.matplotlib('a.svg', figure=figure, sub=inset)
 # display graph (note that only single sage Graphics object has to be
 saved )
 g_ins.save('a.svg', figure=figure, sub=inset)
 UPD: if figures are drawn strangely, add
 aspect_ratio='automatic'
 to matplotlib() parameters. By default it is 1.0, which may be undesired.
 Also, you may want to draw the figure itself, not by Graphics().save()
 function. Replace the last line with the following:
 from matplotlib.backends.backend_agg import FigureCanvasAgg
 figure.set_canvas(FigureCanvasAgg(figure))
 figure.savefig('a.svg')
 }}}
 The user says
 >For some time, I was looking for a way how to generate several sage
 Graphics() objects
 >and plot them on a matplotlib canvas in an arbitrary arrangement, using
 .matplotlib()
 >function. It went out not being straightforward. I decided that the
 solution I've found
 >may be interesting for others as well.

--

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12326#comment:1>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to