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, closes #2323

@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

Copy link
Member

Choose a reason for hiding this comment

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

Debating on whether to use https://github.com/sphinx-doc/sphinxext-rediraffe to add a redirect for this 🤔

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
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
@seisman seisman mentioned this pull request Sep 18, 2025
43 tasks
Comment on lines +208 to +209
# Fill bars with GMT pattern 8, with white background and black foreground.
fill=Pattern(8, bgcolor="white", fgcolor="black"),
Copy link
Member

Choose a reason for hiding this comment

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

At L149 above, could you add an intersphinx link to :class:`pygmt.params.Pattern` ? Then we can properly close #2323.

Copy link
Member Author

Choose a reason for hiding this comment

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

You meant L179, right? Done in 5774b35.

Copy link
Member

@weiji14 weiji14 left a comment

Choose a reason for hiding this comment

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

Looks great overall, approving with some very minor comments.

@@ -1,25 +0,0 @@
# Bit and Hachure Patterns
Copy link
Member

Choose a reason for hiding this comment

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

Debating on whether to use https://github.com/sphinx-doc/sphinxext-rediraffe to add a redirect for this 🤔

images using image raster files.
dpi
Resolution of the pattern in dots per inch (DPI) [Default is 300].
bgcolor/fgcolor
Copy link
Member

Choose a reason for hiding this comment

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

Type hints for these not showing in the docs. Does it matter?

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to make it work but was not successful.

Comment on lines +123 to +124
compressionfill=Pattern(8),
extensionfill=Pattern(31),
Copy link
Member

Choose a reason for hiding this comment

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

Just want to flag that we need to remember to update the type-hints for various *fill parameters to include pygmt.params.Pattern later.

@seisman seisman merged commit bd1dd63 into main Sep 26, 2025
22 of 24 checks passed
@seisman seisman deleted the feature/pattern branch September 26, 2025 01:05
@seisman seisman removed the needs review This PR has higher priority and needs review. label Sep 26, 2025
seisman added a commit that referenced this pull request Sep 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Brand new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Define a class for GMT patterns Gallery example for histogram/plot showing bit and hachure patterns

3 participants