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

workaround for 1 elem hists #1238

Merged
merged 3 commits into from Aug 20, 2021
Merged

workaround for 1 elem hists #1238

merged 3 commits into from Aug 20, 2021

Conversation

SimonDanisch
Copy link
Member

hist([8,8,8,8,8]) would yield histograms with nothing.
With this PR, they get one bar at 8:
image

Not sure if it's the nicest way to set edges to nothing in that case, but since the edges are kind of undefined in that case, most other values would not work out?

@@ -72,6 +72,9 @@ function Makie.plot!(plot::Hist)
edges = lift(values, plot.bins) do vals, bins
if bins isa Int
mi, ma = float.(extrema(vals))
if mi == ma
return nothing
Copy link
Contributor

@piever piever Aug 19, 2021

Choose a reason for hiding this comment

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

Can't we just set

mi, ma = mi - 0.5, ma + 0.5 # EDIT: and maybe `bins = 1` to just get the one bar

and keep all the remaining logic the same? We still get the arbitrary bar of width 1 centered around the unique value, but avoid having to keep two different code paths.

In particular, I think having 2 separate code paths can cause issues with normalization options (for example with normalization = :pdf weights should be 1 instead of values[][1]).

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, thanks :)

@SimonDanisch SimonDanisch changed the title (terrible?) workaround for 1 elem hists workaround for 1 elem hists Aug 20, 2021
src/stats/hist.jl Outdated Show resolved Hide resolved
Co-authored-by: Pietro Vertechi <pietro.vertechi@neuro.fchampalimaud.org>
@SimonDanisch SimonDanisch merged commit cc5da46 into master Aug 20, 2021
@SimonDanisch SimonDanisch deleted the sd/1elemhist branch August 20, 2021 10:10
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.

None yet

2 participants