-
Notifications
You must be signed in to change notification settings - Fork 229
Add the Pattern class for specifying bit and hachure patterns to fill symbols and polygons #4020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
311c83f
to
926a690
Compare
5816270
to
89020a2
Compare
89020a2
to
1571b19
Compare
1571b19
to
ed1ba89
Compare
@@ -1,25 +0,0 @@ | |||
# Bit and Hachure Patterns |
There was a problem hiding this comment.
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
pygmt/params/pattern.py
Outdated
Parameters | ||
---------- | ||
id |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed in f627d28.
pygmt/params/pattern.py
Outdated
[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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reversed
, inversed
, inverted
(or invert
), which one is better?
GMT and GMT.jl use the word invert
for image
's -I
option.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed in 28be123.
There was a problem hiding this 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]>
examples/gallery/symbols/patterns.py
Outdated
# 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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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
: patternP
orp
: invert+b
: bgcolor+f
: fgcolor+r
: dpiExamples:
Pattern(10)
Pattern(10, bgcolor="red", fgcolor="blue", dpi=200, invert=True)
Preview:
Changes in this PR:
Pattern
classPattern
todoc/api/index.rst
examples/gallery/symbols/patterns.py
doc/techref/patterns.md
Closes #2438.