ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 10 Jan 2017 14:06:20 +0100Coloring surfaces in plot3dhttps://ask.sagemath.org/question/9068/coloring-surfaces-in-plot3d/I'm really new with sage, and what I would like is to color a graph from plot3d according to some function (specifically, I would want the hue to vary with the magnitude of the gradient). Is there some way of doing this easily?Wed, 12 Sep 2012 18:16:12 +0200https://ask.sagemath.org/question/9068/coloring-surfaces-in-plot3d/Answer by FrédéricC for <p>I'm really new with sage, and what I would like is to color a graph from plot3d according to some function (specifically, I would want the hue to vary with the magnitude of the gradient). Is there some way of doing this easily?</p>
https://ask.sagemath.org/question/9068/coloring-surfaces-in-plot3d/?answer=36249#post-id-36249Something like that is now possible as follows.
var('x,y,z')
cm = colormaps.winter
f = sin(2*z).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 takes values between 0 and 1.Tue, 10 Jan 2017 14:06:20 +0100https://ask.sagemath.org/question/9068/coloring-surfaces-in-plot3d/?answer=36249#post-id-36249Answer by niles for <p>I'm really new with sage, and what I would like is to color a graph from plot3d according to some function (specifically, I would want the hue to vary with the magnitude of the gradient). Is there some way of doing this easily?</p>
https://ask.sagemath.org/question/9068/coloring-surfaces-in-plot3d/?answer=14029#post-id-14029Yes and no. There is basic functionality for colormaps, as described on the question about [coloring by z-level](http://ask.sagemath.org/question/1405/how-to-color-a-3d-plot-by-z-level). Sage's colormaps come from matplotlib, and you can define your own colormap functions in matplotlib. Here is the documentation for [matplotlib colormaps](http://matplotlib.org/api/cm_api.html).
But I don't know if Sage's interface to matplotlib has been extended to all the functionality of matplotlib (probably not). Perhaps you'll need to import matplotlib and use it's plotting functionality directly . . .
It should be possible, but may require learning more about matplotlib and how to use it. Good luck!Thu, 13 Sep 2012 09:43:52 +0200https://ask.sagemath.org/question/9068/coloring-surfaces-in-plot3d/?answer=14029#post-id-14029Comment by kcrisman for <p>Yes and no. There is basic functionality for colormaps, as described on the question about <a href="http://ask.sagemath.org/question/1405/how-to-color-a-3d-plot-by-z-level">coloring by z-level</a>. Sage's colormaps come from matplotlib, and you can define your own colormap functions in matplotlib. Here is the documentation for <a href="http://matplotlib.org/api/cm_api.html">matplotlib colormaps</a>.</p>
<p>But I don't know if Sage's interface to matplotlib has been extended to all the functionality of matplotlib (probably not). Perhaps you'll need to import matplotlib and use it's plotting functionality directly . . . </p>
<p>It should be possible, but may require learning more about matplotlib and how to use it. Good luck!</p>
https://ask.sagemath.org/question/9068/coloring-surfaces-in-plot3d/?comment=18168#post-id-18168Niles, your ticket http://trac.sagemath.org/sage_trac/ticket/12212 might be relevant here.Sun, 24 Feb 2013 20:30:30 +0100https://ask.sagemath.org/question/9068/coloring-surfaces-in-plot3d/?comment=18168#post-id-18168