3
$\begingroup$

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":

L={1,2,3,4,5,6,8,10};
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[]}

Thanks!

Pedro

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

Grid[coordsandcolors]

enter image description here

$\endgroup$
  • $\begingroup$ Wow, I must admit I don't quite understand how this works, but it does. Thanks a lot! $\endgroup$ – TumbiSapichu Sep 27 at 3:41
  • 2
    $\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 at 3:49
  • $\begingroup$ @AlexeyPopkov, excellent points. (Actually, Normal[P1] was my first try.) $\endgroup$ – kglr Sep 27 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.