2
$\begingroup$

How can I invert the grayscale colors when using MatrixPlot? My data is between 0 and 1 and the color scheme when using GrayLevel is white for 1, black for 0. I do not want to simply invert the data, because in that case the legends won't be correct.

MatrixPlot[data, ColorFunction -> GrayLevel]

$\endgroup$
2
$\begingroup$

Use ColorFunction -> (GrayLevel[1 - #] &) with ColorFunctionScaling -> False:

SeedRandom[1]
data = Rescale @ RandomReal[1, {7, 7}];
mp1 = MatrixPlot[data, ColorFunction -> GrayLevel,
   PlotLegends -> Automatic, ColorFunctionScaling -> False, 
   ImageSize -> 300, PlotLabel -> "GrayLevel"];
mp2 = MatrixPlot[data, ColorFunction -> (GrayLevel[1 - #] &),
   PlotLegends -> Automatic, ColorFunctionScaling -> False, 
   ImageSize -> 300, PlotLabel -> "GrayLevel[1-#]&"];
Row[{mp1, mp2}]

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.