I am plotting histograms with THStack and then taking their ratio, but I am having difficulties in generating titles for their axes, as well as changing the range of the y-axis. Here is the relevant part of my code:
Trying out histStacked.GetYaxis().SetTitle("Frequency") for the y-title takes away the filling from the histograms, and calling ratios.GetXaxis().SetTitle("m_{ll}") for the x-title and histStacked.GetYaxis().SetRange(0,150) or even histStacked.GetYaxis().SetRangeUser(0,150) for the change in y-range has no effect on the plot. Is there perhaps another way of doing this? Any help would be much appreciated!
Hi @dastudillo, that worked great, thanks a lot! With “takes away the filling” I mean that after having filled the histograms with colour (e.g. calling hist1.SetFillColor(kGreen)), if I call histStacked.GetYaxis().SetTitle("Frequency") these fillings are removed.
I think you need to show more code, where are you doing that and so on; I could guess you need to include the option “f” when adding it to the THStack, but there could be other things going on. A complete but small reproducer would be best.
@dastudillo I have written a small, self-contained reproducer: example_histPlot.py (1.9 KB)
The problematic commands are in lines 40 and 69 (I commented a short description of the respective issues). I hope this is clear enough, but let me know if you have further questions.
About 69: the x-axis title does show, but it’s very small (zoom in on the PNG and you’ll see), like the axis labels. You are only changing the title and label font properties for the y-axis, but not for x, so add that (and you’ll need to increase the bottom margin of that pad):