Extract colours from a Palette

I’d like to make a scatter plot, where each point has a different colour determined by a certain number, where that number represents some kind of an occupancy. I’d like to go from blue->green->yellow->red, as occupancy for that spot/data point is increasing. Now, I can do that with a few “if o<1, SetMarkerColor(kBlue)” or something, but then I’d end up having a lot of else if conditions until I get to red, and I’d like to have as many colours as I can.

Is there a way to extract the colours from the Rainbow palette, in which case having the colours would make it easier to make a linear scale with many "else if o<x, SetMarkerColor(…), lines, or is there a way to call the SetMarkerColor function with the colours of the rainbow palette, and somehow connect it to my occupancy based on which I’m colouring the points?



our graphics expert is away, but hopefully this will help you out.
You can loop through all the colours in the palette and assign a colour to your primitives like this:

auto cols = TColor::GetPalette();
// I suppose you have a vector of entities you want to draw here
for (int i=0;i<cols.GetSize() || i >= myObjects.size() ;i++) {


Thanks :slight_smile:
In the end what I did was just extracting the RGB components of a colourmap from MATLAB and made a nx3 array in root, and then using a “for” loop, I added indices to each row of colours, and then I called SetMarkerColor(my_index).

Glad you could solve this!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.