Skip to content
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

clamp_errors options for Makie Errorbars and clamp_bincounts for histograms #118

Merged
merged 9 commits into from
May 30, 2024

Conversation

Moelf
Copy link
Owner

@Moelf Moelf commented May 28, 2024

This is an alternative to #116 @sfranchel

I'm a bit hesitant to clip the error bars to positive

DO NOT MERGE

Blocked by MakieOrg/Makie.jl#3901

The following works on older Makie but not the latest one, I think it's a bug

julia> h = Hist1D(;binedges=0:1, bincounts=[0.1], sumw2=[0.1])
edges: [0.0, 1.0]
bin counts: [0.1]
total count: 0.1

julia> stephist(h); errorbars!(h); current_figure()

image

julia> stephist(h); errorbars!(h; error_function=FHist.pearson_err); current_figure()

image

Copy link

codecov bot commented May 28, 2024

Codecov Report

Attention: Patch coverage is 0% with 46 lines in your changes are missing coverage. Please review.

Project coverage is 77.99%. Comparing base (e4bc8ca) to head (4a40c86).
Report is 1 commits behind head on main.

Files Patch % Lines
ext/FHistMakieExt.jl 0.00% 46 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #118      +/-   ##
==========================================
- Coverage   80.37%   77.99%   -2.39%     
==========================================
  Files          11       11              
  Lines         790      818      +28     
==========================================
+ Hits          635      638       +3     
- Misses        155      180      +25     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sfranchel
Copy link
Collaborator

Thanks for looking into this!

I still think it would be very useful to clip both negative/zero values and errors to positive, to do plots in log scale. I'm quite frequently getting into errors for non-compatible values for log scale. It's true that one could avoid it by choosing more wisely the binning of histograms, but when you need to run on high number of events and a bit more complex selections it isn't really obvious what's the best binning, and it's very likely to end up with empty bins. For several MC generators, it's also quite common to get negative weights, which can produce negative valued bins.

So I'd love to have an option to clip bin counts and errors! If you believe this is more of an edge case, we could set it as not being the default behaviour.

@Moelf
Copy link
Owner Author

Moelf commented May 29, 2024

Negative bin counts tell you something is happening with the MC, and users should take conscious decisions about it, we don't want to silently produce incorrect visualization is my take.

I'm happy to clamp error bars automatically

@sfranchel
Copy link
Collaborator

Totally agree that we shouldn't silently produce incorrect visualization, indeed I think it would bet better to not have on this feature by default.

@Moelf
Copy link
Owner Author

Moelf commented May 29, 2024

stephist(h); errorbars!(h; clamp=false); current_figure()

image

julia> stephist(h); errorbars!(h); current_figure()

image

julia> stephist(h); errorbars!(h; error_function=FHist.pearson_err); current_figure()

image

@sfranchel how about this?

@sfranchel
Copy link
Collaborator

Ok, that looks good. Maybe I'd make the default clamp=false, and I'd add the same option for clamping also bin counts in barplots and scatter plots 🙏

@Moelf
Copy link
Owner Author

Moelf commented May 29, 2024

ah, right now it only clamps the error bars -- since it's a keyword argument to the errorbars(), I thought we want to clamp error bars above zero by default, we just didn't want to clamp the bincounts automagically.

Actually, I think for the bincounts(), we should just add clamp() method to histograms themselves?

@Moelf
Copy link
Owner Author

Moelf commented May 29, 2024

julia> h = Hist1D(;binedges=0:2, bincounts=[-0.1, 0.1], sumw2=[0.1, 0.1])
edges: [0.0, 1.0, 2.0]
bin counts: [-0.1, 0.1]
total count: 0.0

julia> clamp_bincounts = true; clamp_errors=true;

julia> stairs(h; clamp_bincounts); errorbars!(h; clamp_bincounts, clamp_errors); current_figure()

Why the default behavior?

  • It's important for people to catch real negative bin counts -- it's an indication of low stats of generated events
  • It's more annoying than helpful to deal with error bars that happen to dip under zero most of the time.
- clamp_bincounts = false (default) clamp_bincounts = true
clamp_errors = false image Don't do this
clamp_errors = true (default) image image

@Moelf
Copy link
Owner Author

Moelf commented May 29, 2024

one caveat is that until MakieOrg/Makie.jl#3904 is addressed, hist() and stephist() won't be able to use clamp_bincounts = true, you need to directly use barplot() and stairs(). They are the same, but it is a bit annoying

@Moelf
Copy link
Owner Author

Moelf commented May 29, 2024

julia> h = Hist1D(;binedges=0:2, bincounts=[-0.1, 0.1], sumw2=[0.1, 0.1])
edges: [0.0, 1.0, 2.0]
bin counts: [-0.1, 0.1]
total count: 0.0

julia> clamp_bincounts = true; clamp_errors=true;

julia> barplot(h; clamp_bincounts); errorbars!(h; clamp_bincounts, clamp_errors); current_figure()
- clamp_bincounts = false (default) clamp_bincounts = true
clamp_errors = false image Don't do this
clamp_errors = true (default) image image

@Moelf
Copy link
Owner Author

Moelf commented May 29, 2024

for completeness: scatter plot:

image

@Moelf Moelf changed the title error_function options for Makie Errorbars clamp_errors options for Makie Errorbars and clamp_bincounts for histograms May 29, 2024
@Moelf Moelf requested a review from sfranchel May 29, 2024 20:36
@sfranchel
Copy link
Collaborator

Thanks a lot @Moelf , this looks great!! Very much appreciated

@Moelf Moelf merged commit 30a4197 into main May 30, 2024
6 of 8 checks passed
@Moelf Moelf deleted the errorbar_options branch May 30, 2024 20:02
@Moelf Moelf mentioned this pull request May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants