I need to get the color from cells of the plot built by ArrayPlot[] or MatrixPlot[] for later use in, e.g., Style[] or other functions

  • 4
    $\begingroup$ I think the most robust solution would be to generate the list of colors yourself, rather than trying to extract it from the output of those functions. To this end, take a look at ColorFunction and ColorFunctionScaling to understand how the colors are generated from the color function, and see e.g. this question for the default color function used by Mathematica. $\endgroup$
    – Lukas Lang
    Oct 18, 2022 at 7:33
  • $\begingroup$ OK, I'll try to learn these issues in more details for this task $\endgroup$
    – Konstantin
    Oct 18, 2022 at 8:30
  • 1
    $\begingroup$ I agree with the first comment especially that the colors might change each time the matrix is changed . For one particular matrix, a possibility (with some issues) might be to use something like MatrixPlot[Array[#1 + #2 &, {4, 4}]] // DominantColors however it adds white among the colors due to the background. The white color might or might not be in the original plot. Also you might need to specify options at times and it might not work as you wish at times. $\endgroup$ Oct 18, 2022 at 14:03

1 Answer 1


You could extract them from the plot

plot = ArrayPlot[{{1, 0, 0, 0.3}, {1, 1, 0, 0.3},
    {1, 0, 1, 0.7}}, ColorRules -> {1 -> Pink, 0 -> Yellow}];

colours = RGBColor @@@ Union[Catenate[plot[[1, 1]]]]

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.