On 5/7/11 5:00 PM, ObsessiveMathsFreak wrote:
I still can't get this code to work.

In lieu of any external solutions, I've tried to hack something
together in sage itself, using the standard 3d functionality.
Basically it involves drawing a series of implicit plot 3d countours,
then cutting into them with a small plane and drawing a 2d countour
based on that plane. I also found it useful to make the plotting
interactive. It's better than nothing I suppose. Here is some example
code

var('x y z u v')
f=lambda x,y,z: (y-x^2)+sin(z)
F=lambda X: f(X[0,0],X[1,0],X[2,0])

#3D level countours of function
p_slices=sum([ implicit_plot3d(f(x,y,z)==w, (x, -3, 3), (y, -3,3), (z,
-3,3),opacity=0.1,color="green") for w in [-1,-0.5,..,1] ])

@interact
def _(phi = slider(-pi/2,pi/2,pi/20,default=pi/2),theta = slider(-
pi,pi,pi/20,default=0),\

x0=slider(-1,1,0.1,default=0),y0=slider(-1,1,0.1,default=0),z0=slider(-1,1,0.1,default=0),
\
     R=slider(0.1,10,0.1,default=1)):


p=matrix([x0,y0,z0]).transpose()
#center of 2D plot
     e1=matrix([cos(theta)*sin(phi), sin(theta)*sin(phi), -
cos(phi)]).transpose()    #u axis of 2D plot
     e2=matrix([-sin(theta), cos(theta),
0]).transpose()                             #v axis of 2D plot

     V=lambda u,v: p
+u*e1+v*e2                                                       #map
u,v to x,y,z

     #pcon=density_plot(F(V(u,v)),(u,-R,R),(v,-R,R),cmap="gray")
     pcon=contour_plot(F(V(u,v)),(u,-R,R),(v,-
R,R),cmap="gray",fill=false)
     pcon.set_aspect_ratio(1)

     pplane=parametric_plot3d( [V(u,v)[0,0],V(u,v)[1,0],V(u,v)[2,0]],
(u,-R,R),(v,-R,R),opacity=0.6,color="red") #location of plane in 3D

     (pplane+p_slices).show(aspect_ratio=[1,1,1])
     show(pcon)


However, once again I find myself frustrated by plot3ds refusal to
allow itself to be position beside other plots. Consequently, the
plots will not all fit in one screen for me.

Yes, this has frustrated me too.



The other major problem is the complete and total lack of colour
coding of plots. Does anyone know of a way to control the colour
output of 2D countour plots or density plots, so as to make the colour
scheme consisten across both the 2D and 3D plots (or at least to stop
the colour scheme rescaling every time the 2D square plane segment is
moved.


We haven't wrapped the equivalent of the vmin and vmax parameters from the matrix_plot yet. You can use the matrix_plot to specify hard limits for the top and bottom colors of a colormap:

http://www.sagemath.org/doc/reference/sage/plot/matrix_plot.html

It should be straightforward to add the same functionality to contour and density plots. If you need it right away, you might use matplotlib in the meantime, which is what we use underneath things to do 2d plots.

Jason

--
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to