Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

I am trying to plot a parametric circle in rainbow colors. It should go round once, but I'd like to be able to make it go round the rainbow an arbitrary amount of times.

I currently have:

ParametricPlot3D[{Sin[u] Sin[Theta], Cos[u] Sin[Theta], 
  Cos[Theta]} /. Theta -> Pi/6, {u, -Pi, Pi}, 
  PlotStyle -> Directive[Thickness[.01]], 
  ColorFunction -> Function[{x, y, z}, ColorData["Rainbow"][(Arg[x + I y] + Pi)/(2 Pi)]]]

Which I think should choose a color from the ColorData named Rainbow (which changes only between 0 and 1 (the result of Arg lies between -Pi and Pi, so adding Pi and dividing the resulting interval by 2 Pi will give me a number between 0 and 1) depending on the angle of the circle. I get an almost decent result if I divide by Pi/2 instead of 2 Pi: Nearly rainbow circle

But I have no idea why there is yellow and green twice. I'm certainly missing something, does anyone know what?

share|improve this question

marked as duplicate by Artes, Michael E2, Silvia, Oleksandr R., Sjoerd C. de Vries Jun 13 '13 at 19:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Look up ColorFunctionScaling. –  J. M. Jun 13 '13 at 13:23
    
@0x4A4D Adding ColorFunctionScaling->False "fixes" it. But why would it being set to True mess up my own scaled values? –  rubenvb Jun 13 '13 at 13:37
    
If you look at the docs, you'll see that with the setting ColorFunctionScaling -> True, the x and y are scaled even before being fed to your color function; that's different from scaling Arg[], the output. –  J. M. Jun 13 '13 at 13:42
    
Related: mathematica.stackexchange.com/q/25871/5478 –  Kuba Jun 13 '13 at 14:54

2 Answers 2

Since you're providing the scaling, you don't want Mathematica to do it, so

ParametricPlot3D[{Sin[u] Sin[Theta], Cos[u] Sin[Theta], Cos[Theta]} /. Theta -> Pi/6, 
   {u, -Pi, Pi}, 
   PlotStyle -> Directive[Thickness[.1]], 
   ColorFunction -> 
     Function[{x, y, z}, ColorData["Rainbow"][(Arg[x + I y] + Pi)/(2 Pi)]],
   ColorFunctionScaling -> False]

enter image description here

share|improve this answer

Building on m_goldberg's answer, you can also use Hue instead of Rainbow -- this provides brighter colors and is still pretty much around the rainbow.

ParametricPlot3D[{Sin[u] Sin[Theta], Cos[u] Sin[Theta], 
             Cos[Theta]} /. Theta -> Pi/6, {u, -Pi, Pi}, 
         PlotStyle -> Directive[Thickness[.1]], 
         ColorFunction -> Function[{x, y, z}, Hue[(Arg[x + I y] + Pi)/(2 Pi)]], 
         ColorFunctionScaling -> False, Boxed -> False, Axes -> False]

enter image description here

share|improve this answer

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