# Why does StreamColorFunctionScaling refuse to turn off?

Consider this simple streamline plot:

StreamPlot[{-y/10, x/10}, {x, -1, 1}, {y, -1, 1},
StreamColorFunction -> Function[{x, y, u, v}, Hue[v]]]


The arguments to the colour function are rescaled to lie between 0 and 1, so the colours span the whole spectrum, as expected.

But now I want to turn off colour function scaling and work with the original vector field values. Those lie between -1/10 and 1/10, so I should get only hues between purple and orange:

StreamPlot[{-y/10, x/10}, {x, -1, 1}, {y, -1, 1},
StreamColorFunction -> Function[{x, y, u, v}, Hue[v]],
StreamColorFunctionScaling -> False]


I'm sorry, Dave. I'm afraid I can't do that.

Is this a bug? How do I work around it?

-
If I Print out the values of x, y, u and v that are being passed to the color function, v is not x/10, which is surprising. –  The Toad May 15 '14 at 17:39
The scaling is "affected" by turning off StreamColorFunctionScaling, but not in the correct way. It's definitely not a behavior that a sane person would expect. But Mathematica is probably thinking it's doing what's best for the mission... –  Jens May 15 '14 at 17:42
Thanks for pointing this out. I've reported it, and we'll take a look. –  rcollyer May 15 '14 at 20:57
"I'm sorry, Dave." LOL –  Mr.Wizard May 15 '14 at 21:36
@rcollyer: You should take a look at ChadK's answer. As far as I can tell, the bug is that Mathematica's behaviour is inconsistent with its documentation. –  Rahul May 15 '14 at 22:03

The StreamColorFunction has different arguments than you expect. It is actually like this: {x, y, u/um, v/um, um}, where $um = Sqrt[u^2+v^2]$.

So all you need to do is redefine your function to account for this:

StreamPlot[{-y/10, x/10}, {x, -1, 1}, {y, -1, 1},
StreamColorFunction -> Function[{x, y, u, v, um}, Hue[u*um]],
StreamColorFunctionScaling -> False]


-
Welcome to the site, and thanks for your contribution. Please consider selecting a more "human" name, by the way. –  Mr.Wizard May 15 '14 at 21:52
But what if I rescale everything by choosing the plot function and range as {-y/100,x/100},{x,0,10},{y,0,10}? It's wrong again. I don't think the order you're assuming works correctly. –  Jens May 15 '14 at 21:55
It looks like this works. Thanks! –  Rahul May 15 '14 at 22:01
Yes, it works after correcting the order of arguments. –  Jens May 15 '14 at 22:07
What are the chances that someone signed up just to answer my question? I feel honoured. :) –  Rahul May 15 '14 at 22:20

A work-around:

vv = {};
StreamPlot[{-y/10., x/10.}, {x, -1, 1}, {y, -1, 1},
StreamColorFunction -> (AppendTo[vv, #4] &)];

With[{MinMax = Through[{Min, Max}[vv]]},
StreamPlot[{-y/10., x/10.}, {x, -1, 1}, {y, -1, 1},
StreamColorFunction -> (Hue[Rescale[#4, MinMax, {-.1, .1}]] &)]
]


-
You should probably find the Min and Max values of vv outside of the Function, and inject them; as written this runs that part repeatedly. It may or may not matter but it seems like bad style. –  Mr.Wizard May 15 '14 at 21:37
I am going to take the liberty of making the change described above. If you don't like it you can revert it. –  Mr.Wizard May 15 '14 at 21:40
@Mr.Wizard, Just noticed you comment. Thank you for the edit. –  kguler May 15 '14 at 21:43