Skip to content

Histogram giving incorrect representation of data #391

@heron1

Description

@heron1

Description

Chart.Histogram seems to not accurately reflect the underlying data, unless I'm misunderstanding how things work.

Repro steps

Consider the code:
let rnd = System.Random()
let x =
    [ for i = 0 to 1000000 do
          yield rnd.NextDouble() ] //double range from 0 to 1
let histo1 = Chart.Histogram(X = x, NBinsX = 5) 

histo1 |> Chart.show

This shows a histogram chart with a non-even distribution of what should be evenly distributed numbers (5 bins, each 0.2 in size, from 0 to 1). In fact, bin 0-0.2, and bin 0.8-1 show only 100k elements, whilst bins 0.2-0.4, 0.4-0.6, 0.6-0.8 show 200k elements - a 50% error.

Expected behavior

There should be an even distribution. This can be confirmed by running the following code after the above code:

let counts = List.groupBy (fun t ->
                match t with
                | x when x < 0.2 -> 1
                | x when x < 0.4 -> 2
                | x when x < 0.6 -> 3
                | x when x < 0.8 -> 4
                | _ -> 5) x
                |> List.map (fun (group, x) -> x.Length)
printfn $"counts: {counts}"

(the counts are evenly distributed)

Related information

  • Windows 10
  • Master
  • .NET 6, F# Interactive

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions