TH2F surf1 plot transparent colors

Hi there,

I’ve trouble with getting transparent colors on a TH2F plot with the surf1 drawing option.

Currently I have a TH2F ‘3D’ plot that shows a FFT spectrum (y: 1-1000Hz) for certain time measurements (x: range: 0-140s) drawn with the ‘surf1’ option. The z-axis is basically the FFT amplitude (workaround, because TGraph2D is too slow). I’ve attached an example.

Now i want to superimpose this plot with another plot that has the same properties but another dataset. The superimposed plot should be transparent such that one can see if the 2nd dataset somewhere has higher amplitudes than the first dataset.

I’ve now tried to do this with a THStack (written in Pyroot, but I think you can understand what I’m doing):

hist2D = ROOT.TH2F('hist2D', 'test, Amplitude; Time [s]; Frequency [hz]',
               160, 0, 140, 200, 0, 1000)
hist2DHStack = ROOT.TH2F('THStack', 'test2, Amplitude; Time [s]; Frequency [hz]',
               160, 0, 140, 200, 0, 1000)

[fill histograms...]

HStack = ROOT.THStack("hs","Stacked 2D histograms")

canvas.SaveAs('HStackSurfaceCH' + Channel + '.pdf','pdf')

outputfile = ROOT.TFile('HStackCH' + Channel + '.root','RECREATE')

Now, how can I get a transparent palette for the hist2DHStack histogram without changing the palette for the first histogram in the HStack? If I use gStyle->SetPalette(), the colors for the first histogram will obviously be changed too.
And how can I do that in a TBrowser, or can I save these drawing options to the root file?

I’ve also tried the hist->SetFillColorAlpha(kBlue, 0.35) command, but I always get an “AttributeError: ‘TH2F’ object has no attribute ‘SetFillColorAlpha’” error. However I guess this method wouldn’t work anyways, as I need to define a color palette for my surf1 plot and not a single Fill Color.

Anyone has an idea?

I also have another different question to the same plot:
If i wanted to superimpose the hist2D with surf1 drawing option with a surface defined by a function, how would I do that? Basically I’d like to see if some of the hist2D peaks are above a certain threshold (and the treshold is dependent on the frequency defined by the function).
Maybe I could fill another histogram with calculated values with aid of the function that I define, add the histogram to the THStack and then make it transparent, but is that the easiest way (and it would still look quite weird I guess)? Or is there a way to add a TF2 to the THStack?

Thanks a lot!

I use root_v5.34.14.
Spectrum.pdf (910 KB)

You can make the palette transparent with the last parameter of

[quote=“couet”]you can make the palette Transparent with the last parameter os gStyle->SetPalette() … SetPalette[/quote]

Yes I can do that, however this changes the transparency for both histograms in the HStack and not just for one?

You need two palettes.

Sorry for the late response, I mistakenly didn’t check the notification option.

Thanks alot, two color palettes should do the trick!

However I’m struggling with the PyROOT syntax for ROOT.SetPalette().
I tried the following, however this results in a surf plot with white fill color.

zeroes = [0]
Zeroes = array('i', zeroes)
ROOT.gStyle.SetPalette(55, Zeroes, 0.3)

I’ve read that Wim has implemented a proper nullpointer ([Problems setting palette however it isn’t in my ROOT version because I get an exception if I call it.

ROOT.gStyle.SetPalette(55, 0.3)

also obviously yields a type error.

Another thing that worries me with the link that you’ve provided is that I have a THStack, so that I can only draw once. However if I only draw once, I can’t use the TExec1 + TExec2 method

# 2 histograms:

# Single THStack:

Thanks in advance.

Can you post a C++ macro reproducing the issue ?
Note that transparency does not wot with X11.