Ask Your Question
2

How to color a 3d plot by z-level?

asked 2012-05-09 23:27:40 +0100

calc314 gravatar image

updated 2012-05-09 23:28:35 +0100

I'd like to color a 3d plot based on z-level. I think this is easy to do in Maple or Mathematica, but I've been searching the web for help on doing this in Sage and can't find anything to help with plot3d or implicit_plot3d.

Here's the implicit_plot3d I'm using.

var('x,y,z')    
implicit_plot3d(x^2-y^2*z == 0,(x,-4,4),(y,-4,4),(z,-4,4)).show(mesh=True)

Also, are there color maps in Sage that produce plots with colors and lighting similar to the default in Mathematica?

edit retag flag offensive close merge delete

Comments

Niles also eventually opened up the possibly relevant http://trac.sagemath.org/sage_trac/ticket/12212

kcrisman gravatar imagekcrisman ( 2013-02-24 20:30:19 +0100 )edit

3 Answers

Sort by » oldest newest most voted
5

answered 2017-01-10 14:00:38 +0100

FrédéricC gravatar image

updated 2017-09-14 14:43:53 +0100

This is now possible as follows.

var('x,y,z')
cm = colormaps.autumn
f = (z/4).function(x,y,z)
implicit_plot3d(x^2-y^2*z == 0,(x,-4,4),(y,-4,4),(z,-4,4), color=(f,cm))

where cm is a chosen colormap among those available. Beware that the coloring function f must take values between 0 and 1.

edit flag offensive delete link more

Comments

1

Nice! Thanks!

calc314 gravatar imagecalc314 ( 2017-01-10 14:44:27 +0100 )edit

(In fact, apparently it's been available for well over a year! Nice necro-post, Frédéric!)

kcrisman gravatar imagekcrisman ( 2017-01-10 15:46:23 +0100 )edit
2

answered 2012-05-10 10:32:53 +0100

niles gravatar image

updated 2012-05-10 10:35:19 +0100

I asked a similar question about using a colormap for implicit_plot3d almost a year ago, and it is still open. @schilly did show how to use matplotlib colormaps for plot3d though, and it's pretty cool:

sage: var('r v')
sage: cmsel = [colormaps['autumn'](i) for i in sxrange(0,1,0.05)]
sage: p = plot3d(0.2*(r**2 + v**2) + cos(2*r)*sin(2*v),(r,-2,2), (v,-2,2), adaptive=True, color=cmsel)
sage: p.show(aspect_ratio=(1,1,1), figsize=[7,3])

image description

And, as @jason-grout said, you can see all of the available colormaps with colormaps.keys().

If you do figure out some way to use colormaps with implicit 3d plots, I would love to hear about it!

edit flag offensive delete link more

Comments

Wow! That does a great job. It would still be great to have it built into the plot3d and implicit_plot3d commands so that it is more friendly and intuitive.

calc314 gravatar imagecalc314 ( 2012-05-10 11:30:11 +0100 )edit
1

answered 2012-05-10 00:21:01 +0100

Shashank gravatar image

Have a look at this. Is this what you are looking for? You can run matplotlib scripts in sage.

http://matplotlib.sourceforge.net/exa...

edit flag offensive delete link more

Comments

That code does produce some good looking plots. However, it is too involved for me to use with calculus students without writing some sort of wrapper for it. Also, I definitely cannot take this as a solution to a colleague who is not an expert programmer. Are there simpler options to get this result?

calc314 gravatar imagecalc314 ( 2012-05-10 10:26:40 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-05-09 23:27:40 +0100

Seen: 4,039 times

Last updated: Sep 14 '17