Draw TH2D COLZ and overlay a CONT1 with values from z-axis


I would like to make a plot containing two histograms, one drawn with COLZ option and one drawn with CONT1. I would like the colors used for the contours (predefined) to match up to the corresponding colors of the first histograms z-axis TPaletteAxis. But I can’t work out how to do the contour plot without altering the COLZ plot’s palette.

Here’s what I mean (lets say both histograms contain values ranging from 0 to 1).:

TPaletteAxis* p = (TPaletteAxis*)hist1->GetListOfFunctions()->FindObject("Palette");

double contours[5] = {0.7,0.8,0.9,0.95,0.99};

int cols[5];
for(int i=0;i<5;i++) cols[i] = p->GetValueColor(contours[i]);



The problem with the above code is that the call to gStyle->SetPalette causes the COLZ plot to pick up this new, very limited set of colors. Is it possible to draw the contour plot and specify the set of colors to use, without changing the gStyle palette?



root.cern.ch/drupal/content/how- … ame-canvas


Is it possible to change the draw style for the contours too, but keep the set of colours I have defined?

what do you mean by that ?

Sorry, I meant the line style. So have all the contours drawn with a particular line style. But I figured it out, just SetLineStyle worked, so that’s fine.