2
$\begingroup$

I have a GraphicsGrid of MatrixPlots in the range between 0 and 1 and I want to show a single legend for all of the grid with the appropriate color range.

I tried:

Row[{GraphicsGrid[
   Table[Graphics[
     MatrixPlot[RandomReal[1, {10, 10}], Frame -> False, 
      FrameTicks -> False, ColorFunction -> "TemperatureMap"]], {x, 1,
      10}, {y, 1, 10}]], BarLegend[{"TemperatureMap", {0, 1}}]}]

But the legend's color range does not match those of the graphics. Is there an alternative way to generate a legend?

I found two posts with a similar topic, but I'm not sure how to apply this to my data

$\endgroup$

1 Answer 1

4
$\begingroup$

Almost there, you problem is, that ColorFunction automaticly rescales. You can change this with ColorFunctionScaling -> False.

So you get:

Row[
 {
  GraphicsGrid[
   Table[Graphics[
     MatrixPlot[RandomReal[1, {10, 10}], Frame -> False, 
      FrameTicks -> False, ColorFunction -> "TemperatureMap", 
      ColorFunctionScaling -> False]], {x, 1, 10}, {y, 1, 10}]
   ],
  BarLegend[{"TemperatureMap", {0, 1}}]
  }
 ]

Which works like intended:

enter image description here

(Well, i would increase the size of the Graphics, but this can easily done by ImageSize-Option) Like so:

enter image description here

$\endgroup$
3
  • $\begingroup$ Thank you! That works well! I was wondering if there is a way to adapt the color for the legend to the graphics instead of the other way around? $\endgroup$
    – holistic
    Commented May 5, 2017 at 19:14
  • $\begingroup$ You could simply define your own colorfunction and apply it inside the graphics and use it for the legend. I recommend, you take a look at Blend . $\endgroup$ Commented May 6, 2017 at 0:43
  • $\begingroup$ Great, thank you :)! $\endgroup$
    – holistic
    Commented May 6, 2017 at 7:15

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.