I am looking for any ideas about how to colorize an ellipsoid with a custom gradient style or by a Blend function. I would like to colorize ellipsoid as follows:

  • at $(5,0,0)$ and $(-5,0,0)$ should be red color,
  • at $(0,2,0)$ and $(0,-2,0)$ should be green color
  • at $(0,0,2)$ and $(0,0,-2)$ should be blue color

All other points should be interpolated, respectively to their locations.

I tried to use Blend function, but something went wrong.

My code:

ParametricPlot3D[{5 Cos[u] Cos[v], 2 Cos[v] Sin[u], 2 Sin[v]},
{u, 0, 2 Pi, Pi/10}, {v, -Pi/2, Pi/2, Pi/10}, Axes -> False, 
Boxed -> False, Mesh -> None, 
ColorFunction ->Function[u, v, 
Blend[{Red, Green, Blue}, {5 Cos[u] Cos[v], 2 Cos[v] Sin[u], 2 Sin[v]}]]]
  • $\begingroup$ Did you possibly mean Function[{u,v},Blend[...]]? $\endgroup$
    – celtschk
    Commented Mar 31, 2012 at 19:37
  • $\begingroup$ Thanks! But unfortunately, it renders me something similar to arc in three-dimensional space. $\endgroup$
    – Tomasz
    Commented Mar 31, 2012 at 20:03

1 Answer 1


There are a few things wrong with your code. First of all, the ranges for the parameters are in the wrong format. They should be of the form {u, umin, umax} etc. If you want to control the step size you could use PlotPoints and MaxRecursion.

Secondly, as celtschk pointed out, the arguments in a pure function should be combined in a list. If you check the documentation of ColorFunction, you'll see that for ParametricPlot3D, the arguments provided to the ColorFunction are in this case the three spacial coordinates $x, y, z$ and the two parameters $u, v$ in that order. Therefore you could define your ColorFunction for example as

Function[{x, y, z, u, v}, Blend[{Red, Green, Blue}, {(x/5)^2, (y/2)^2, (z/2)^2}]

You would also need to set ColorFunctionScaling -> False. With these settings, the ellipsoid then becomes something like

ParametricPlot3D[{5 Cos[u] Cos[v], 2 Cos[v] Sin[u], 2 Sin[v]}, {u, 0, 
  2 Pi}, {v, -Pi/2, Pi/2}, Axes -> False, Boxed -> False, Mesh -> None,
 PlotPoints -> 40,
 ColorFunctionScaling -> False, 
 ColorFunction -> Function[{x, y, z, u, v}, Blend[{Red, Green, Blue}, 
   {(x/5)^2, (y/2)^2, (z/2)^2}]]]

Mathematica graphics

  • $\begingroup$ Thank you @Heike for clear explanation! I'm not very familiar with Mathematica. I'am Matlab user, but unfortunately my University changed to Mathematica. $\endgroup$
    – Tomasz
    Commented Mar 31, 2012 at 20:25
  • 5
    $\begingroup$ @user897 I would say fortunately... Welcome to the club $\endgroup$ Commented Mar 31, 2012 at 21:14
  • $\begingroup$ @user897 A high quality answer as usual from Heike. I would like to point out that you do not need to include the trailing unused arguments in the Function, so you could use Function[{x, y, z}, . . .] (I presume she included them for didactic clarity). Also, you can use an anonymous or "pure" function, but so as not to run into precedence problems you should wrap the whole thing in ( ) until you understand more: ColorFunction -> (Blend[{Red, Green, Blue}, {(#/5)^2, (#2/2)^2, (#3/2)^2}] &) $\endgroup$
    – Mr.Wizard
    Commented Apr 1, 2012 at 4:29
  • 1
    $\begingroup$ @SjoerdC.deVries: If fortunately or unfortunately depends on what you need. Mathematica has abilities which AFAIK are not found in Matlab (esp. symbolic calculation), but if you don't need them and have considerable experience in Matlab, having to learn a new syntax to just do the same things you already did in Matlab is a disadvantage to you. Also I'd be surprised if there was not some area where Matlab is better (well, there definitely exists at least one: executing existing Matlab code!). There's almost always a case where the more general tool is worse than a more specialized one. $\endgroup$
    – celtschk
    Commented Apr 1, 2012 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.