3
$\begingroup$

I try to use Manipulate to specify my interactive own colors and scaling for the ColorFunction in ListContourPlot. In the forum I found this very useful code

 Manipulate[{a, x, y, z, b} = 
  Rescale[{aa, xx, yy, zz, bb}, MinMax@{aa, xx, yy, zz, bb}];
 colors = 
  Transpose[{{a, x, y, z, b}, {Blue, Lighter@LightBlue, White, Yellow,
      Red}}];
 DensityPlot[
  Sin[x] Cos[y], {x, -2 \[Pi], 2 \[Pi]}, {y, -2 \[Pi], 2 \[Pi]}, 
  ColorFunction -> (Blend[colors, #] &), PlotLegends -> Automatic, 
  PlotPoints -> 100], {{aa, 0, "Blue"}, 0, 
  1, .01}, {{xx, 0.25, "Lighter@LightBlue"}, 0, 
  1, .01}, {{yy, .5, "White"}, 0, 1, .01}, {{zz, .75, "Yellow"}, 0, 
  1, .01}, {{bb, 1, "Red"}, 0, 1, .01}]
Dynamic[colors]

How can I adapt it for my ColorFunction and my data instead of Sin[x] Cos[y]

myTemperatureMap[f_] := 
  Blend[{{-1, Blue}, {-0.25, Lighter@LightBlue}, {-0.25, White}, {0, 
     White}, {0.3, Yellow}, {0.6, Red}}, f];


data = Import[file, "Table", HeaderLines -> 2]; 
dataT = Transpose[data];
dataT = {dataT[[1]]*10, dataT[[2]]*10, dataT[[3]]}; 
dataT[[3]] = Rescale[dataT[[3]], MinMax[dataT[[3]]], {-1., 1.}];

ListContourPlot[data,
  PlotRange -> {{-0.05, 0.05}, {-0.05, 0.05}, {-1., 1.}},
  ColorFunction -> myTemperatureMap, ColorFunctionScaling -> False, 
  ContourStyle -> None, Contours -> 200,
  PlotLegends -> 
   BarLegend[{myTemperatureMap[#] &, {-1, 1}}, 
    LegendMarkerSize -> 300, 
    LabelingFunction -> (Style[NumberForm[#, {Infinity, 2}], Bold, 
        Black, 12] &)]];

I tried this but doesn't work the color doesn't change...

Manipulate[{a, x, y, z, b} = Rescale[{aa, xx, yy, zz, bb}, MinMax@{aa, xx, yy, zz, bb}];
colors = Transpose[{{a, x, y, z, b}, {Blue, Lighter@LightBlue, White, 
    Yellow, Red}}];
 ListContourPlot[data,
  ColorFunction -> myTemperatureMap, ColorFunctionScaling -> False, 
  ContourStyle -> None, Contours -> 200,
  PlotLegends -> 
   BarLegend[{myTemperatureMap[#] &, {-1, 1}}, 
    LegendMarkerSize -> 300, 
    LabelingFunction -> (Style[NumberForm[#, {Infinity, 2}], Bold, 
        Black, 12] &)]], {{aa, 0, "Blue"}, -1, 1, .01}, {{xx, 0.25, "Lighter@LightBlue"}, -1, 1, .01}, {{yy, .5, "White"}, -1, 1, .01}, {{zz, .75, "Yellow"}, -1, 1, .01}, {{bb, 1, "Red"}, -1, 1, .01}]
Dynamic[colors]
$\endgroup$
4
  • $\begingroup$ do you get the desired result if you change the lower limit of controls to -1,, e.g. {{bb, 1, "Red"}, -1, 1, .01} and put your ListContourPlot in place of DensityPlot in Manipulate[...] ? $\endgroup$
    – kglr
    Commented Jun 28, 2018 at 12:41
  • $\begingroup$ I tried this (see edited code) but the colors doesn't change... $\endgroup$ Commented Jun 28, 2018 at 13:08
  • $\begingroup$ And I don't see my plot only the panel... $\endgroup$ Commented Jun 28, 2018 at 13:13
  • $\begingroup$ similar, if not duplicate, post here: mathematica.stackexchange.com/q/64439/9490 $\endgroup$
    – Jason B.
    Commented Jun 28, 2018 at 14:30

1 Answer 1

2
$\begingroup$
data = Table[{#, #2, .8 Sin[#] Cos[#2]} & @@ RandomReal[{-3, 3}, 2], {1000}];

Manipulate[{a, x, y, w, z, b} = 
  Rescale[{aa, xx, yy, ww, zz, bb}, MinMax@{aa, xx, yy, ww, zz, bb}];
 colors = Transpose[{{a, x, y, w, z, b}, {Blue, Lighter@LightBlue, White, 
     White, Yellow, Red}}];
 ListContourPlot[data, ColorFunctionScaling -> False, 
  ColorFunction -> (Blend[colors, #] &), 
  ColorFunctionScaling -> False, ContourStyle -> None, 
  Contours -> 200, 
  PlotLegends -> BarLegend[{Blend[colors, #] &, {-1, 1}}, 
    LegendMarkerSize -> 300, 
    LabelingFunction -> (Style[NumberForm[#, {Infinity, 2}], Bold, Black, 12] &)]], 
  {{aa, -1, "Blue"}, -1,  1, .01}, 
  {{xx, -0.25, "Lighter@LightBlue"}, -1, 1, .01}, 
  {{yy, -.25, "White"}, -1, 1, .01}, 
  {{ww, 0., "White"}, -1, 1, .01}, 
 {{zz, .3, "Yellow"}, -1, 1, .01}, {{bb, .6, "Red"}, -1, 1, .01}]

enter image description here

$\endgroup$
4
  • $\begingroup$ In my case data is a Table of three column. Should I write data = Table[{#,#2,#3}&@@file] because when I replace your data by my data it doesn’t work... $\endgroup$ Commented Jun 28, 2018 at 14:18
  • $\begingroup$ If your data is a list of triples, (data = { {x1,y1, z1},, {x2, y2, z2}, ...,{xn,yn,zn}}) , then it should work. Check Dimensions[data] to make sure it is {somenumber, 3}. $\endgroup$
    – kglr
    Commented Jun 28, 2018 at 14:39
  • $\begingroup$ Ok thanks, I will check it. $\endgroup$ Commented Jun 29, 2018 at 6:39
  • $\begingroup$ I checked, my Dimension is 3. When I run it, it never stop and I get the following message > the Kernel is not responding to Dynamic Evaluation... But otherwise, when I use your function, it works well... $\endgroup$ Commented Jun 29, 2018 at 6:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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