#10775: streamline plots
-------------------------------------------------+-------------------------
       Reporter:  jason                          |        Owner:  jason,
           Type:  enhancement                    |  was
       Priority:  major                          |       Status:  new
      Component:  graphics                       |    Milestone:  sage-6.4
       Keywords:                                 |   Resolution:
        Authors:                                 |    Merged in:
Report Upstream:  Fixed upstream, but not in a   |    Reviewers:
  stable release.                                |  Work issues:
         Branch:                                 |       Commit:
   Dependencies:                                 |     Stopgaps:
-------------------------------------------------+-------------------------

Comment (by kcrisman):

 Here are some
 
[http://matplotlib.org/examples/images_contours_and_fields/streamplot_demo_features.html
 upstream examples].
 ----
 Here is another example from somewhere in this discussion, allowing phase
 plots.  Not directly related but looks nice with such things.
 {{{
 # based on code from oddrobot, http://sagenb.org/home/pub/1532/
 from sage.calculus.desolvers import desolve_system_rk4
 x,y,t=var('x y t')
 class DESolution:
     def __init__(self,system,time_range,initial,stepsize=0.05):

         self.tvar=time_range[0]
         self._times=srange(time_range[1],time_range[2],stepsize)
         self.vars=[v for v,_ in initial]
         self.dim=len(self.vars)
         self._soln=desolve_odeint(system, ics=[v for _,v in initial],
 times=self._times, dvars=self.vars, ivar=self.tvar)

     def phase_plot(self,vars=None,color='blue',**kwargs):
         # find which indices the specified variables are
         if vars is not None:
             vars_index=[self.vars.index(v) for v in vars]
         elif self.dim<=3:
             vars_index=range(self.dim)
         else:
             vars_index=range(2)

         p=line(self._soln[:,vars_index],color=color,**kwargs)
         # add an arrow head showing which way we are going around the
 phase line
         half=int(self._soln.shape[0]/2)
         p+=arrow(self._soln[half,vars_index],
 self._soln[half+1,vars_index],color=color)
         if len(vars_index)==2:
             p.axes_labels([str(self.vars[v]) for v in vars_index])
         return p

     def coordinates(self,colors=None,**kwargs):
         if colors is None:
             colors=rainbow(len(self.vars))
         p=Graphics()
         p+=sum(line(zip(self._times,self._soln[:,i]), color=colors[i],
 legend_label=str(self.vars[i]),**kwargs) for i in range(self.dim))
         return p
 }}}

--
Ticket URL: <http://trac.sagemath.org/ticket/10775#comment:12>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to