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") HStack.Add(hist2DHStack) HStack.Add(hist2D) HStack.Draw('SURF1') canvas.SaveAs('HStackSurfaceCH' + Channel + '.pdf','pdf') canvas.Clear() outputfile = ROOT.TFile('HStackCH' + Channel + '.root','RECREATE') HStack.Write() outputfile.Close()
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)