Skip to content

[hist] Implement AutoZoom of TH1/TH2/TH3/TAxis to filled range #18459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

ferdymercury
Copy link
Contributor

@ferdymercury ferdymercury commented Apr 22, 2025

This Pull request:

Changes or fixes:

Fixes #14538

Checklist:

  • tested changes locally
  • updated the docs (if necessary)

Copy link
Member

@linev linev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

Features was implemented long-long time ago in JSROOT,
now it is time to have it in ROOT.

But several changes are required:

  • exclude loop repetition in TH1::GetRangeOfFilledWeights
  • if TH1::AutoZoom is invoked, it only should affect that histogram and not change zooming in all other histograms in the pad
  • same true for TAxis::AutoZoom - it only should change properties of this axis and not all histograms in the pad
  • but must be checked with superimposed histograms, THStack, TMultiGraph - they all can have side effects
  • fix failures with roottest

Copy link

github-actions bot commented Apr 22, 2025

Test Results

    18 files      18 suites   4d 0h 0m 19s ⏱️
 2 731 tests  2 731 ✅ 0 💤 0 ❌
47 752 runs  47 752 ✅ 0 💤 0 ❌

Results for commit d4400a6.

♻️ This comment has been updated with latest results.

@ferdymercury
Copy link
Contributor Author

  • if TH1::AutoZoom is invoked, it only should affect that histogram and not change zooming in all other histograms in the pad

This is already the behavior 'most of the time'. Only if DrawFrame was called before, the multi-analysis is run.
I was trying to mimick what Unzoom was doing, why should it be different?

@linev
Copy link
Member

linev commented Apr 22, 2025

Only if DrawFrame was called before, the multi-analysis is run.

DrawFrame is special use-case and not used with THStack or TMultiGraph painting.
And Unzoom() can behave differently as AutoZoom().

@linev
Copy link
Member

linev commented Apr 23, 2025

We need to wait with this PR until roottest merged into ROOT master.
Then one can sync all changes in one PR.

@ferdymercury
Copy link
Contributor Author

I thought it was already merged, and I had rebased and synced into one.

@linev
Copy link
Member

linev commented Apr 23, 2025

I tried your code and have several more comments.

  1. For 1-D histogram with few entries TH1::AutoZoom() changes zooming for Y axis which is not nice.
  2. Selected range is exact position of the non-zero bins. If peak is very sharp and has just single bin width - produced result is unusable. One need some default margins on the left and right side of the peak.
  3. If there are several peaks - AutoZoom always show all peaks and not most significant one. Also if histogram already pre-zoomed to some range - peak should be searched in this range.

See my simple demo.
autozoom.C.txt

With THStack method does not work.

With superimposed histograms AutoZoom works only when first histogram is selected - for all others histogram method has no effect. At the same time Unzoom works for all histograms. Here correspondent demo:

autozoom_same.C.txt

@ferdymercury
Copy link
Contributor Author

  1. For 1-D histogram with few entries TH1::AutoZoom() changes zooming for Y axis which is not nice.

I guess that's a feature of "TH1::UnZoom" that is also not nice, that could be handled in a separate PR ?

2. Selected range is exact position of the non-zero bins. If peak is very sharp and has just single bin width - produced result is unusable. One need some default margins on the left and right side of the peak.

I have implemented this now. It could be modified to accept a relative percentage rather than a fixed number of bins if wanted.

3. If there are several peaks - AutoZoom always show all peaks and not most significant one.

I do not understand what you mean. I am proposing AutoZoom to show all peaks, rather than the most significant.

3. Also if histogram already pre-zoomed to some range - peak should be searched in this range.

I kind of disagree, sometimes I like to zoom in to see a specific thing, and then AutoZoom to zoom out to the filled range. Maybe ZoomToFit is a better word for the function??

With superimposed histograms AutoZoom works only when first histogram is selected - for all others histogram method has no effect.

I had made a mistake. Is now fixed, thanks for finding out. You need though to click on the x-axis and click on AutoZoomAll, not AutoZoom. An equivalent function can be created in the TH1::AutoZoomAll if you think it's worth.

With THStack method does not work.

Support has been added now, via TAxis::AutozoomAll.

@linev
Copy link
Member

linev commented Apr 24, 2025

Still, AutoZoom on simple TH1 with few entries changes Y-zoom,
And current range is not taken into account when search for the range.

@ferdymercury
Copy link
Contributor Author

Still, AutoZoom on simple TH1 with few entries changes Y-zoom

But Unzoom does the same, it's changing that too. It's zooming in rather than out.

And current range is not taken into account when search for the range.

Yes, but I argue that that's intended. Autozoom in matplotlib works also like that.

@linev
Copy link
Member

linev commented Apr 24, 2025

But Unzoom does the same, it's changing that too. It's zooming in rather than out.

Then one need to fix Unzoom too. It is not nice behavior.

Autozoom in matplotlib works also like that.

Use-case is simple. One makes approx zooming with mouse and then call method to get peak fully displayed.
Therefore behavior of matplotlib is not best approach here.

thanks to linev
Default drawing histogram option is to leave a YMARGIN range of 10% in YMAX. So if you call Unzoom, it was calling GetMaximum, which calculated the exact maximum, and then called SetMaximum, thus overwriting the stored value. Use instead GetMaximumStored to prevent recalculation if not set by user.
@ferdymercury
Copy link
Contributor Author

Then one need to fix Unzoom too. It is not nice behavior.

Last commit tries to fix that.

@dpiparo
Copy link
Member

dpiparo commented Apr 27, 2025

@couet @linev is this ready to be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ROOT-5125] Autozoom functionality for TH1/TH2/TH3 or TAxis classes
4 participants