2
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ "From the great answer of Mr.Wizard..." — could you please also link to that answer? $\endgroup$ – rm -rf Jun 14 '13 at 3:39
  • $\begingroup$ 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? $\endgroup$ – rm -rf Jun 14 '13 at 3:42
  • $\begingroup$ mathematica.stackexchange.com/questions/13046/… $\endgroup$ – Loscuro Jun 14 '13 at 4:46
  • $\begingroup$ 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. $\endgroup$ – Loscuro Jun 14 '13 at 4:50
  • $\begingroup$ 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. $\endgroup$ – rm -rf Jun 14 '13 at 5:07
2
$\begingroup$

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

$\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.