Skip to content

Conversation

seisman
Copy link
Member

@seisman seisman commented Jul 27, 2025

This PR implements the Pattern class, which is a more Pythonic syntax to specify patterns as fill.

The GMT upstream documentation is at https://docs.generic-mapping-tools.org/dev/reference/features.html#specifying-area-fill-attributes.

The GMT CLI syntax is: -GP|ppattern[+bcolor][+fcolor][+rdpi]

The PyGMT parameters are

  • pattern: pattern
  • P or p: invert
  • +b: bgcolor
  • +f: fgcolor
  • +r: dpi

Examples:

  • Pattern(10)
  • Pattern(10, bgcolor="red", fgcolor="blue", dpi=200, invert=True)

Preview:

Changes in this PR:

  • Implement the Pattern class
  • Add Pattern to doc/api/index.rst
  • Add tests
  • Update examples that use pattern as fills
  • Update gallery example examples/gallery/symbols/patterns.py
  • Remove the unnecessary documentation doc/techref/patterns.md

Closes #2438.

@seisman seisman force-pushed the AliasSystem/params/base branch from 311c83f to 926a690 Compare July 29, 2025 04:39
@seisman seisman added the feature Brand new feature label Sep 7, 2025
Base automatically changed from AliasSystem/params/base to main September 8, 2025 03:39
@seisman seisman changed the title WIP: Add the Pattern class Add the Pattern class for specifying bit and hachure patterns to fill symbols and polygons Sep 8, 2025
@seisman seisman added this to the 0.17.0 milestone Sep 8, 2025
@@ -1,25 +0,0 @@
# Bit and Hachure Patterns
Copy link
Member Author

Choose a reason for hiding this comment

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

This documentation describes the syntax for GMT CLI, which no longer makes sense. with the Pattern class, so this file will be deleted in this PR.

The image for the 90 predefined patterns will be shown at https://pygmt-dev--4020.org.readthedocs.build/en/4020/api/generated/pygmt.params.Pattern.html

Parameters
----------
id
Copy link
Member Author

Choose a reason for hiding this comment

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

For this parameter, is id good? Or should we use pattern?

Copy link
Member

Choose a reason for hiding this comment

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

I would use pattern, as it looks like that id is already reserved by Python for something else.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed in f627d28.

[Default is white for background and black for foreground]. Setting either to
an empty string will yield a transparent background/foreground where only the
foreground or background pixels will be painted.
reversed
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I think I like invert. For me, it describes better that the fore- and background colors of the pattern are flipped, and it is shorter than inverted.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed in 28be123.

@seisman seisman marked this pull request as ready for review September 8, 2025 15:32
@seisman seisman added the needs review This PR has higher priority and needs review. label Sep 8, 2025
@seisman seisman requested a review from Copilot September 9, 2025 02:39
@seisman seisman requested a review from Copilot September 9, 2025 02:39
Copilot

This comment was marked as outdated.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces the Pattern class, providing a Pythonic interface for specifying bit and hachure patterns to fill symbols and polygons in PyGMT, replacing the previous string-based pattern syntax.

  • Implements a new Pattern dataclass with validation for pattern IDs, colors, and resolution
  • Updates examples and documentation to use the new class instead of string patterns
  • Removes outdated technical reference documentation about pattern strings

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pygmt/params/pattern.py Core Pattern class implementation with validation and GMT string generation
pygmt/tests/test_params_pattern.py Comprehensive test suite for Pattern class functionality
pygmt/params/init.py Exports Pattern class from params module
examples/tutorials/basics/polygons.py Updates documentation reference from patterns to Pattern class
examples/tutorials/advanced/focal_mechanisms.py Replaces string patterns with Pattern class instances
examples/tutorials/advanced/cartesian_histograms.py Updates histogram fill to use Pattern class
examples/gallery/symbols/patterns.py Major refactor demonstrating Pattern class usage
doc/techref/patterns.md Removes outdated pattern string documentation
doc/techref/index.md Removes reference to deleted patterns.md
doc/api/index.rst Adds Pattern to API documentation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Yvonne Fröhlich <[email protected]>
Comment on lines 34 to 35
# By default, the pattern is plotted in black and white with a resolution of 300 dpi.
# By default, a pattern is plotted in black and white with a resolution of 1200 dpi.
Copy link
Member

Choose a reason for hiding this comment

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

Did the default change from 300 dpi to 1200 dpi? Or was 300 dpi wrong / a typo?

Copy link
Member Author

@seisman seisman Sep 9, 2025

Choose a reason for hiding this comment

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

The upstream documentation says 1200, but the source code says 300. Actually it's a typo in the upstream documentation. See PR GenericMappingTools/gmt#8789 for details.

Fixed in e9eca8e.

@seisman seisman requested a review from a team September 10, 2025 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Brand new feature needs review This PR has higher priority and needs review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Define a class for GMT patterns
2 participants