Skip to content

Figure.histogram: Add parameters to annote bars and deprecate parameter 'annotate' - #4895

Open
seisman wants to merge 13 commits into
mainfrom
histogram/annot
Open

seisman wants to merge 13 commits into
mainfrom
histogram/annot

Conversation

@seisman

@seisman seisman commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

This PR provides a Pythonic implementation for the -D option. The GMT CLI syntax is:

-D[+b][+f<font>][+o<offset>][+r]

This PR maps it to multiple parameters

  • annot
  • +b: annot_position [default to "top"]
  • +f: annot_font
  • +o: annot_offset
  • +r: annot_orientation

The prefix annot is preferred so that it's more consistent with Figure.colorbar and Frame. This PR also deprecates the annotate parameter to annot.

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=10,
    fill="red3",
    pen="1p",
    annot=True,
    annot_position="top",
    annot_font="8p,blue",
    annot_orientation="vertical",
    # horizontal=True, 
)
fig.show()

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

@seisman seisman added this to the 0.20.0 milestone Sep 16, 2026
@seisman seisman added enhancement Improving an existing feature deprecation Deprecating a 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 Sep 28, 2026
@seisman
seisman requested a lite review from Copilot September 28, 2026 15:36

This comment was marked as low quality.

Comment thread pygmt/src/histogram.py Outdated
Comment thread pygmt/src/histogram.py Outdated
Comment thread pygmt/src/histogram.py
Comment on lines +162 to +166
annot_font
Font of the annotations [Default is :gmt-term:`FONT_ANNOT_PRIMARY`].
annot_offset
Offset between a bar and its annotation, with an optional
:ref:`dimension unit <dimension-units>` [Default is ``"6p"``].

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having default = None and then giving a explicit default could be a bit confusing.

Image

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this style is used in the whole documentation. None means using the default value.

Comment thread pygmt/src/histogram.py Outdated

def _alias_option_D( # ruff: ignore[invalid-function-name]
annot: bool = False,
annot_position: Literal["top", "bottom"] = "top",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For histograms with horizontal bars, it is left and right. Maybe we could use something simliar to start and end?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 0394768.

Comment thread pygmt/src/histogram.py Outdated
seisman and others added 8 commits September 29, 2026 07:24
Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com>
Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com>
Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com>

This branch has not been deployed

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

Labels

deprecation Deprecating a feature enhancement Improving an existing feature final review call This PR requires final review and approval from a second reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants