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

normalization = : pdf argument in hist plot does not normalize correctly #3780

Open
3 tasks done
danielchen26 opened this issue Apr 10, 2024 · 1 comment
Open
3 tasks done
Labels

Comments

@danielchen26
Copy link

danielchen26 commented Apr 10, 2024

  • are you running newest version (version from docs) ?

    • yes
    • (temp) pkg> st
      status `~/documents/temp/project.toml`
        [13f3f980] cairomakie v0.11.9
        [ee78f7c6] makie v0.20.8
      
  • can you reproduce the bug with a fresh environment ? (]activate --temp; add Makie)

    • yes
  • What platform + GPU are you on?

    • mac

issues for the following code:

using CairoMakie
testd = 0.5 * randn(1000) .+ 3.5
testd2 = 0.2 * randn(1000) .+ 5.5

hist(testd .+ testd2, normalization = :pdf, bar_labels = :values,
     label_formatter=x-> round(x, digits=2), label_size = 15,
     strokewidth = 0.5, strokecolor = (:black, 0.5), color = :values)
Screenshot 2024-04-10 at 3 32 03 PM The normalization is wrong here.
@asinghvi17 asinghvi17 changed the title normalization = : pdf argument in hist plot using Cairomakie does not normalize correctly normalization = : pdf argument in hist plot does not normalize correctly Apr 12, 2024
@asinghvi17
Copy link
Member

asinghvi17 commented Apr 12, 2024

This is a StatsBase issue and should probably be raised there. Consider the following:

julia> h = StatsBase.fit(StatsBase.Histogram, testd .+ testd2)
Histogram{Int64, 1, Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}
edges:
  7.0:0.5:11.0
weights: [6, 34, 158, 326, 315, 131, 27, 3]
closed: left
isdensity: false

julia> h_norm = StatsBase.normalize(h; mode = :pdf)
Histogram{Float64, 1, Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}
edges:
  7.0:0.5:11.0
weights: [0.012, 0.068, 0.316, 0.652, 0.63, 0.262, 0.054, 0.006]
closed: left
isdensity: true

julia> h_norm = StatsBase.normalize(h; mode = :probability)
Histogram{Float64, 1, Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}
edges:
  7.0:0.5:11.0
weights: [0.006, 0.034, 0.158, 0.326, 0.315, 0.131, 0.027, 0.003]
closed: left
isdensity: false

So you will probably get what you're looking for using normalization = :probability.

I'll close this issue for now, since it's not a problem we can solve in Makie directly.

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

No branches or pull requests

2 participants