Skip to content

histogram: Support density histograms and more #9212

Description

@seisman

Currently, GMT's histogram supports counts and frequency (in percentage) histograms via the -Z option. There are some other useful histograms, e.g., density histogram, which is not supported by GMT yet.

For comparison, matplotlib's hist methods supports "counts" and "density" histograms, while seaborn's histplot method supports more types (see the stat parameter):

  • count: show the number of observations in each bin [Supported by GMT]
  • frequency: show the number of observations divided by the bin width [Not supported by GMT]
  • probability or proportion: normalize such that bar heights sum to 1 [Not supported by GMT]
  • percent: normalize such that bar heights sum to 100 [Supported by GMT, but GMT calls it "frequency_percent"]
  • density: normalize such that the total area of the histogram equals 1 [Not supported by GMT]

Here's the math summarized by Claude [the correctness is not confirmed yet].

With n = count in a bin, N = total data points, w = the bin's width.

stat formula bars sum to area under bars
count n N N·w
frequency n / w N/w N
probability (alias proportion) n / N 1 w
percent 100·n / N 100 100·w
density n / (N·w) 1/w 1

percent is just probability × 100, so there are really only four distinct quantities. density is the only one that is both normalized and per-unit-x, which is why it's the one with area = 1 and the only one directly comparable to a probability density function.

Activity

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions