2
$\begingroup$

I use the following line to plot my graphic. I have defined the following function for the color of my graphic myTemperatureMap[f_] := Blend[{{-1, Blue}, {-0.25, Lighter@LightBlue}, {-0.25, White}, {0, White}, {0.3, Yellow}, {0.6, Red}}, f]; and I use the following line to plot my graphic

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

I get the following image enter image description here

However, I would like to see my BarLegend between -1 to 1 with 0 in the middle. How to change the range in my BarLegend ? I Tried to change Automatic to {"myTemperatureMap",{-1,1}} in BarLegend but it is not working...

$\endgroup$
  • $\begingroup$ does BarLegend[{Automatic, {-1, 1}}, LegendMarkerSize -> 300] work? $\endgroup$ – kglr Jun 28 '18 at 7:13
  • $\begingroup$ No, there is no difference $\endgroup$ – Bigprophete Jun 28 '18 at 7:15
  • $\begingroup$ it works in v9, it doesn't in v11. $\endgroup$ – kglr Jun 28 '18 at 7:25
  • $\begingroup$ BarLegend[{myTemperatureMap[#] &, {-1, 1}}, LegendMarkerSize -> 300] works v11 too. $\endgroup$ – kglr Jun 28 '18 at 7:27
  • $\begingroup$ I use v11. Last one works. Thanks $\endgroup$ – Bigprophete Jun 28 '18 at 7:29
2
$\begingroup$
data = Table[{#, #2, .8 Sin[# ] Cos[#2]} & @@ RandomReal[{-3, 3}, 2], {1000}];

graph2 = ListContourPlot[data, ColorFunction -> myTemperatureMap, 
  ColorFunctionScaling -> False, ContourStyle -> None,  Contours -> 200, 
  PlotLegends -> BarLegend[Automatic, LegendMarkerSize -> 300]]

enter image description here

Changing BarLegend[Automatic, LegendMarkerSize -> 300] to

BarLegend[{myTemperatureMap[#]& , {-1,1}} , LegendMarkerSize -> 300]

we get

enter image description here

| improve this answer | |
$\endgroup$

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.