Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

From the great answer of Mr. Wizard, I would like to learn how to implement the associated PlotLegends scaled too. Here is the simplest example with PlotLegends, which does not look to be scaled:

data = {{{2, 4, 5, 4}, {3, 3, 7, 2}, {7, 2, 6, 5}, {7, 4, 8, 2}}, 
        {{2, 1, 7, 9}, {3, 2, 1, 8}, {3, 3, 9, 7}, {0, 9, 7, 9}}, 
        {{2, 2, 9, 0}, {5, 7, 0, 9}, {6, 9, 1, 9}, {5, 3, 8, 8}}};

Table[ListDensityPlot[Rescale[data[[i]], {0, 9}], 
ColorFunctionScaling -> False, Mesh -> All, 
ColorFunction -> "TemperatureMap", PlotLegends -> Automatic], {i, 1, 4}]

The first legend shows a different scale from the other three.

share|improve this question
    
"From the great answer of Mr.Wizard..." — could you please also link to that answer? –  rm -rf Jun 14 '13 at 3:39
    
The first legend looks different because the max value is 8/9 < 1, whereas in the rest, it is 9/9 == 1. Perhaps you were looking for the 3 argument form of Rescale? –  rm -rf Jun 14 '13 at 3:42
    
    
What is crucial is that I am using DensityPlot, not ListDensityPlot (tha was an example), on many functions. But the color scale should be exactly the same on the plots as well as on the plot legends. –  Loscuro Jun 14 '13 at 4:50
    
The actual plotting function doesn't really matter, as the issue is that of rescaling. It would be helpful to move the rescaling operation to the color function, as it can then be used with both DP and LDP. Please see the ColorFunction I used in this answer. Specifically, it uses the 3 argument version of Rescale to scale the input so that it is between fixed limits. Of course, this also requires that you know a priori, the min/max of your function/list, but it is easy to workaround it if you don't. –  rm -rf Jun 14 '13 at 5:07
show 7 more comments

1 Answer

Maybe you can try this:

data = {{{2, 4, 5, 4}, {3, 3, 7, 2}, {7, 2, 6, 5}, {7, 4, 8, 2}}, {{2,
  1, 7, 9}, {3, 2, 1, 8}, {3, 3, 9, 7}, {0, 9, 7, 9}}, {{2, 2, 9, 
 0}, {5, 7, 0, 9}, {6, 9, 1, 9}, {5, 3, 8, 8}}};

Table[ListDensityPlot[Rescale[data[[i]], {0, 9}], 
ColorFunctionScaling -> False, Mesh -> All, 
ColorFunction -> "TemperatureMap", 
PlotLegends -> BarLegend["TemperatureMap"]], {i, 1, 3}]

Result:

enter image description here

To see all available colors you can use:

Table[ListDensityPlot[Rescale[data[[i]], {0, 9}], 
ColorFunctionScaling -> False, Mesh -> All, ColorFunction -> #, 
PlotLegends -> BarLegend[#]], {i, 1, 3}] & /@ 
ColorData["Gradients"]

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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