Skip to content

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

Open
seisman wants to merge 2 commits into
mainfrom
histogram/distribution
Open

seisman wants to merge 2 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()

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improving an existing feature needs review This PR has higher priority and needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant