Figure.histogram: Improved syntax for filling bars by position/value - #4886
Open
seisman wants to merge 3 commits into
Open
Figure.histogram: Improved syntax for filling bars by position/value#4886seisman wants to merge 3 commits into
seisman wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The updated fill docstring currently contradicts the implemented/tested behavior for CPT-based fills and should be corrected before approval.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates Figure.histogram to support a more Pythonic way to request CPT-based bar filling by extending the existing fill parameter to accept special values ("position" and "value"), while keeping the legacy cmap (-C) syntax working.
Changes:
- Extend
histogram(fill=...)to accept"position"/"value"and translate them into the appropriate-C/-C+bCLI behavior. - Add image-based regression tests for the new
fillsyntax and the legacycmapsyntax. - Add a new baseline image for the histogram fill behavior.
File summaries
| File | Description |
|---|---|
pygmt/src/histogram.py |
Implements the new fill="position"/fill="value" syntax and maps it onto -C / -C+b. |
pygmt/tests/test_histogram.py |
Adds pytest-mpl image tests covering both new and legacy CPT fill syntaxes, plus an error case. |
pygmt/tests/baseline/test_histogram_fill.png |
Adds the new baseline image used by the pytest-mpl tests. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
37 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In
histogram, bars can be filled by a constant color/pattern, or by the bin position or value (count, frequency). This is achieved by the-Coption, with a syntax like-C<cmap>+b.This PR implements a Pythonic syntax for such features by extending the existing parameter
fill(alias of-G). In addition to color or pattern, nowfillcan accept two special values:"position"and"value".GMT CLI and PyGMT comparison
Here is a comparison:
-Gredfill="red"-Gp5fill=Pattern(5)-Cfill="position"-Ctest.cptfill="position", cmap="test.cpt"test.cpt-C+bfill="value"-Ctest.cpt+bfill="value", cmap="test.cpt"test.cptExamples
Alternative implementation
An alternative implementation is to keep
fillunchanged, but alias-Cto two separate parameters,cmapandfill_by_value(or any other names). The cons are:fillandfill_by_value-Gcan't be used with-C, so we need to deal with conflicts betweenfillandcmap/fill_by_valuecarefullyAddress #4251