Probably, it has been already asked, but the proposed solutions (SetUserRange) could not work for me - What I want to do, is this - I do have collection of TH1 , and want to redraw all of them in a dynamic way so to omit the empty parts of the histos - For example, how is it possible to get rid of the empty left and right bins like in the attached histo ? I dont really care keeping or not the initial number of bins.
For a THStack you will need to loop over the contained histograms, or use the “last” histogram which contains the sum. See this discussion regarding the same issue in PyROOT:
Although this works in principle, the problem is that only the last histo of the stack (the sum) is drawn, meaning that you loose the color-code due to the “stacking” in the first place - In other words, how would be possible to change the range dynamically, but still get the full collection of the TStack in the final plot ?
You should use the “SUM” only for the purpose of finding the first and the last nonzero bins. Draw the “full” THStack (e.g. with “NOSTACK”) and then “limit” the x-axis according to the found nonzero bins.
Note: you MUST draw the THStack BEFORE you can retrieve its x-axis. You might also make sure that it is really drawn by calling “gPad->Modified(); gPad->Update();”.