TBox and color Palette

Hello,
I’m having trouble with the color palette if i try to paint it without an associated histogram.
I would like to draw different TBox with different colors, and associate the colors to a Palette, and draw the associated TPaletteAxis.
Is there a way to draw a color palette without matching it to a histogram or without drawing a histogram?
Thank you in advanced,

You can surely draw the Palette alone but you will have to do the matching with the boxes yourself. Have a look at THistPainter::PaintColorLevels to see how to do the color association. Note that we will soon provide (next release) TH2Poly histograms which will allow to have histogram with any polygonal bins… may be it might be helpful for you ?

Thank you for your quick reply couet.
I’ve had a loot at THistPainter::PaintColorLevels and as far as i have understood, i should build a 1d histogram with the range of values to be associated with the colors, but i really don’t know how to paint the palette once the association is made.
So essentially, on a high level, what i would do is:
TH1F h1=new TH1F();
/

Here it comes the association of values and colors:
Myvalue->MyColor
and then set the histogram colors for each bin?
h1->SetFillColor(gStyle->GetColorPalette(MyColor));
h1->TAttFill::Modify()
*/
And to draw the palette:
h1->PaintPalette();

Is that right?

Thank you,

You do not need an histogram you can do:

   Int_t ncolors, theColor;
   Double_t zmin = fH->GetMinimum();
   Double_t zmax = fH->GetMaximum();
   
   ncolors   = gStyle->GetNumberOfColors();
      
   [...]
   TBox *b;
   while (some_box_to_draw) {
      [...]
      b = ... ;
      box-content = ... ;
      theColor = (Int_t)( ((box-content-zmin)/(zmax-zmin))*(ncolors-1) );
      b->SetFillColor(gStyle->GetColorPalette(theColor));
      b->TAttFill::Modify();
      b->Draw();
   }

This is the way i was doing it to assign the values to the colors, but then, i don’t know how to paint the palette (ie, the vertical axis with the colors) as the only way i know to paint it, is through a histogram. Is there another way?
Thank you for your guidance.

the palette painting is done in THistPainter::PaintPalette

OK. I will use this method as guidance.
Thank you for your help.