Skip to content

Figure.histogram: Improve parameters 'distribution' and 'distribution_pen' to draw distribution curves - #4894

Merged
seisman merged 8 commits into
mainfrom
histogram/distribution
Oct 7, 2026
Merged

seisman merged 8 commits into
mainfrom
histogram/distribution

Conversation

@seisman

@seisman seisman commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

In histogram, the -N option draws the distribution curve. It's in the form of -N[<mode>][+p<pen>], in which <mode> can be 0, 1, or 2 for different modes, and the option can be repeated when needed, and each curve can have different pen settings via +p.

Currently, -N option is aliased to distribution, so the syntax is like distribution="0+p1p,red", distribution=["0+p1p,red", "1+p1p,blue"].

This PR proposes a new syntax with two parameters distribution and distribution_pen:

GMT CLI Old New
-N distribution=True distribution=True*
-N1 distribution=1 distribution="median"
-N1+p1p,red distribution="1+p1p,red" distribution="median", distribution_pen="1p,red"
-N0+p1p,red -N1+p1p,red -N2+p1p,red distribution=["0+p1p,red", "1+p1p,red", "2+p1p,red"] distribution=["mean", "median", "lms"], distribution_pen="1p,red"
-N0+p1p,red -N1+p1p,blue -N2+p1p,yellow distribution=["0+p1p,red", "1+p1p,blue", "2+p1p,yellow"] distribution=["mean", "median", "lms"], distribution_pen=["1p,red", "1p,blue", "1p,yellow"]

*Supported for backward compatibility, but it's not recommended, because it's unclear which curve is drawn

Example

import numpy as np
import pygmt
from pygmt.params import Axis, Frame

rng = np.random.default_rng(seed=100)
mean = 100  # mean of distribution
stddev = 25  # standard deviation of distribution
data = rng.normal(loc=mean, scale=stddev, size=521)


fig = pygmt.Figure()
fig.histogram(
    data=data,
    frame=True,
    series=5,
    fill="red3",
    pen="1p",
    distribution=["mean", "median", "lms"],
    distribution_pen=["1p,blue", "1p,red", "1p,green"],
)
fig.show()

Preview: https://pygmt-dev--4894.org.readthedocs.build/en/4894/api/generated/pygmt.Figure.histogram.html#pygmt.Figure.histogram

@seisman seisman added this to the 0.20.0 milestone Sep 16, 2026
@seisman seisman added enhancement Improving an existing feature needs review This PR has higher priority and needs review. labels Sep 16, 2026
@seisman seisman added final review call This PR requires final review and approval from a second reviewer and removed needs review This PR has higher priority and needs review. labels Oct 2, 2026
@seisman
seisman requested a review from a team October 2, 2026 13:09
@seisman
seisman merged commit a7f1614 into main Oct 7, 2026
22 of 23 checks passed
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Oct 7, 2026
@seisman
seisman deleted the histogram/distribution branch October 7, 2026 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improving an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant