I have the following list of parametric equations

lst = {10*Cos[u]*Sin[v], 3*Sin[u]*Sin[v], 2*Cos[v]};

I define the following color function

colFun = Function[{u, v}, Hue[Rescale[dam, {0, 1}]]]; 


dam = Sqrt[(1296*Cos[u]^4*Sin[v]^4)/
           (900*Cos[v]^2 + 36*Cos[u]^2*Sin[v]^2 + 400*Sin[u]^2*Sin[v]^2)^2 +
           (3600*Cos[u]^2*Sin[v]^2*(9*Cos[v]^2 + 4*Sin[u]^2*Sin[v]^2))/
           (900*Cos[v]^2 + 4*(9*Cos[u]^2 + 100*Sin[u]^2)*Sin[v]^2)^2]; 

So I get the following parametric plot

g = ParametricPlot3D[lst, {u, 0, 2*Pi}, {v, 0, Pi},
        Mesh -> False, 
        PlotStyle -> Opacity[0.8],
        ColorFunction -> colFun, 
        ColorFunctionScaling -> False]

What I want now is to create a color bar which will accompany g. This color bar will show the values of

Rescale[dam, {0, 1}]

The coloring of course will be again according to the same defined color function.

I am looking for a solution that works with Mathematica 8.

  • 1
    $\begingroup$ You can select each piece of code you wrote, and press the {} button in the editor toolbar. This will fix the formatting of the code. $\endgroup$
    – Szabolcs
    Jul 4 '14 at 13:13
  • $\begingroup$ You can try BarLegend. Something like Legended[g, BarLegend[{colFun,{min,max}}]] $\endgroup$
    – Szabolcs
    Jul 4 '14 at 13:15
  • $\begingroup$ Szabolcs thank you very much for your advices regarding my query and as well as the appearance of the post. $\endgroup$
    – Dimitris
    Jul 4 '14 at 13:19
  • $\begingroup$ Unfortunately, I do not have Mathematica 9. I work with version 8. As I saw, BarLegend is a new built-in function introduced in version 9. $\endgroup$
    – Dimitris
    Jul 4 '14 at 13:24
  • $\begingroup$ Szabolcs thanks for adding the required tag. $\endgroup$
    – Dimitris
    Jul 4 '14 at 13:30

This is not a full solution, but it illustrates how I would proceed using Mathematica 8:

colourBar = 
 DensityPlot[y, {x, 0, 1}, {y, 0, 1}, AspectRatio -> 5, 
  PlotRangePadding -> 0, 
  FrameTicks -> {{None, Range[0, 1, .1]}, {None, None}}, 
  ColorFunction -> Hue]

Row[{Show[g, ImageSize -> Medium], 
  Show[colourBar, ImageSize -> Small]}]

enter image description here

It needs extra work to get the formatting right.

You can also look at this package, but I can't offer help with its use.

  • $\begingroup$ Do you mean now = not?? $\endgroup$ Jul 4 '14 at 14:53
  • $\begingroup$ @bobthechemist Yes, I did! $\endgroup$
    – Szabolcs
    Jul 4 '14 at 14:59
  • $\begingroup$ Szabolcs I really appreciate your kind interest. Thank you once again. It was exactly what I need! I have only one query. Is is possible to use another "color palette" instead of Hue? If you see the color bar begins with almost Red (for values close to zero) and ends with red. This may be to Hue[0] and Hue[1] both evaluate to red. Graphics[{Hue[0], Disk[]}] $\endgroup$
    – Dimitris
    Jul 4 '14 at 15:24
  • $\begingroup$ It would be perfect if for instance orange was closer to red in this "color bar". Is it possible? Should I use a different function in lieu of Hue? $\endgroup$
    – Dimitris
    Jul 4 '14 at 15:32
  • $\begingroup$ @dimitris Check the predefined colour palettes (look up ColorData and Color Schemes in the palettes menu), or you can build your own using Blend. $\endgroup$
    – Szabolcs
    Jul 4 '14 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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