GenericMappingTools / GenericMappingTools/gmt

histogram: Support density histograms and more

Open
#9,212 0 comments 0 reactions 1 assignee Claimed by @Esteban82 View on GitHub
feature request
Dominant language
C
Stars
979
Forks
414
Avg merge
17h 26m
Merged PRs (30d)
54

Description

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](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hist.html) methods supports "counts" and "density" histograms, while [`seaborn`'s `histplot`](https://seaborn.pydata.org/generated/seaborn.histplot.html) 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.