4

I use the following code How can I create an interactive ColorFunction using Manipulate? to create my dynamic color. If I succeded to create the slider between -1 to 1, I can't see the first colors (Blue color) which has the negative value -1. My legend bar (see picture) start from light blue not blue I don't understand why...

My Legend Bar

With[{cmax = 12},(*maximum number of colors*)
     DynamicModule[{k = 6, 
       cols = {Blue, LightBlue, White, White, Yellow, Red}, 
       vals = {-1, -0.41, 0.45, 0.5, 0.75, 1.}}, 
      Panel[Column[{Column[{Row[{Dynamic[
              Style["colors: " <> IntegerString[k], Bold]], Spacer[20], 
             Slider[Dynamic[k, (k = #; cols = PadRight[cols, k, Gray];  
                 vals = Rescale[ArrayPad[vals, {0, k - Length[vals]}, "Extrapolated"]]) &], {2, cmax, 1}]}], 
           Dynamic[Multicolumn[
             Array[Column[{ColorSlider[Dynamic[cols[[#]]]], 
                 Row[{Dynamic[Style[vals[[#]], Small, Bold]], Spacer[20], 
                   Slider[Dynamic[vals[[#]]], {-1, 1}, 
                    ImageSize -> Small]}]}] &, k], 6, 
             Appearance -> "Horizontal"], TrackedSymbols :> {k}]}], 
         Dynamic[With[{cl = Transpose[{vals, cols}]}, 
           Column[{Panel[LinearGradientImage[Blend[cl, #] &, {600, 60}]], 
             Button["Copy to clipboard", 
              CopyToClipboard[Defer[Blend[cl, f]]], ImageSize -> Medium, 
              Method -> "Queued"]}]]]}]]]]
Bigprophete
  • 399
  • 1
  • 11

1 Answers1

4

It boils down to how to control the domain used to create the image. As we can see it is {0, 1} by default (see details section in documentation).

LinearGradientImage[ Blend[{{-1, Blue}, {0, Yellow}, {1, Red}}, #] &]

I failed to understand how to assume different domain using DataRange and LinearGradientImage in general so let's proceed with manual Rescale.

You need to edit the line in the code with:

LinearGradientImage[
  Blend[cl, Rescale[#, {0, 1}, MinMax[vals]]] &
, {600, 60}
]

Please let the author of the gui know.

Kuba
  • 136,707
  • 13
  • 279
  • 740