I'm wondering if it is possible to get the list of RGBColor from a plot.

What I mean is simple. Suppose I plot list L with "TemperatureMap":

P1=ListPlot[L,ColorFunction -> ColorData["TemperatureMap"]]

Getting a simple plot:

enter image description here

Can I retrieve from the graphics object P1, the list of RGBColor elements used? (i.e. the color values for each dot in the ListPlot)

colorList= {RGBcolor[],...,RGBcolor[]}



coordsandcolors = DeleteDuplicates @ Cases[P1, GraphicsComplex[coords_, __, 
   VertexColors -> colors_] :> Transpose[{coords, RGBColor @@@ colors}], All][[1]]


enter image description here

| improve this answer | |
  • $\begingroup$ Wow, I must admit I don't quite understand how this works, but it does. Thanks a lot! $\endgroup$ – TumbiSapichu Sep 27 '19 at 3:41
  • 3
    $\begingroup$ It is worth to note that ListPlot behaves this way only in version 12.0. In version 11.3 it produces a plot with all the points of identical color. And in version 12.0 we have a bug: applying Normal changes the plot to the previous version's styling (just removes VertexColors information). $\endgroup$ – Alexey Popkov Sep 27 '19 at 3:49
  • $\begingroup$ @AlexeyPopkov, excellent points. (Actually, Normal[P1] was my first try.) $\endgroup$ – kglr Sep 27 '19 at 3:53

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.