11
$\begingroup$

(by making a mistake) I realised that ColorFunctionScaling can take a list of numerical arguments rather than just booleans. The following is true for ContourPlot and DensityPlot but not Plot3D and haven't searched further. The first argument seems to affect the endpoint values of the scaling and the second argument the gradient (although not entirely sure about this statement). Anyway, here's what I mean:

GraphicsGrid@Table[ContourPlot[x, {x, 0, 2}, {y, -1, 1}, 
   ColorFunctionScaling -> {i, j},
   Frame -> False], 
{i, -1, 2, .5}, {j, -1, 2, .5}]

enter image description here

My questions are:

  • Is this a feature?
  • How, if at all, can I control it accurately in a way that two contour plots, say ContourPlot[x, {x, 0, 2}, {y, -1, 1}] and ContourPlot[x, {x, -2, 0}, {y, -1, 1}] can have a common colour reference without resorting to redefining the ColorFunction and setting the scaling to false?
  • Does it affect other plotting functions?
$\endgroup$
  • 2
    $\begingroup$ Framed@GraphicsGrid@Table[ ContourPlot[x, {x, 0, 2}, {y, -1, 1}, Frame -> False, PlotLabel -> {i, j}, Contours -> 40, ImageSize -> 200, ## ] , {i, -2, 2, 2}, {j, -2, 2, 2} ] & @@@ { {ColorFunctionScaling -> {i, j}, ColorFunction -> (Hue[#] &)}, {ColorFunction -> (Hue[(j - i) #] &)} } but don't ask me why. $\endgroup$ – Kuba Jul 22 '16 at 9:10
  • $\begingroup$ AHA!!! But... WHY!?!?!? And also, why just Contour/Density plots (because one argument passed to colorfunction?). $\endgroup$ – gpap Jul 22 '16 at 9:13
  • 2
    $\begingroup$ And what have I told you at the end? :P $\endgroup$ – Kuba Jul 22 '16 at 9:15
  • $\begingroup$ Also, this only works for integer values (fractional values are different. Which begs the question... WHY!? $\endgroup$ – gpap Jul 22 '16 at 9:17
6
$\begingroup$

Nice find. I think that this is simply giving the equivalent of a DataRange over the z (density) values. Put another way it is providing the third parameter of Rescale:

enter image description here

That lets us conveniently do something like this:

DensityPlot[
  x, {x, -12, 0}, {y, -1, 1}
  , ColorFunctionScaling -> {385, 745}
  , ColorFunction -> "VisibleSpectrum"
]

enter image description here

Correlation with Rescale:

Rescale[Range[-12, 0, 1/2], {-12, 0}, {385, 745}]

ColorData["VisibleSpectrum"] /@ % // Row
{385, 400, 415, 430, 445, 460, 475, 490, 505, 520, 535, 550, 565,
 580, 595, 610, 625, 640, 655, 670, 685, 700, 715, 730, 745}

enter image description here

The behavior exists within the low level Visualization`Core`DensityPlot function:

Visualization`Core`DensityPlot[x, {x, -12, 0}, {y, -1, 1}, 
  ColorFunctionScaling -> {385, 745}, ColorFunction -> "VisibleSpectrum"]

This is a non-end-user-readable function so I will have difficulty tracking it further. However if anyone has a counterexample to my supposition above please let me know and I shall attempt to revise my conjecture.

|improve this answer|||||
$\endgroup$
  • $\begingroup$ Hi, thanks for the answer (+1). So then this means this is useless right? In the sense that it has overlapping functionality with ScalingFunction which is more versatile i.e. in this example, you can set ColorFunctionScaling->False and replicate the same result with ScalingFunctions -> {None, None, (365/12 # + 745) &} $\endgroup$ – gpap Jul 25 '16 at 9:23
  • $\begingroup$ @gpap I wouldn't say it is useless. Lots of things can be done in many different ways, especially in Mathematica. This doesn't make all but one method useless. One could also use ColorFunctionScaling -> True and ColorFunction -> (ColorData["VisibleSpectrum"][385 + 360 #] &). $\endgroup$ – Mr.Wizard Jul 25 '16 at 16:12
  • 1
    $\begingroup$ I agree, what I meant is that the option has limited functionality whereas both alternatives can do that and much more. In any case, this seems to be the answer so tick for you. Thanks again! $\endgroup$ – gpap Jul 26 '16 at 9:15

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.