-
Notifications
You must be signed in to change notification settings - Fork 224
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
Add a gallery example showing how to use patterns via the "fill" parameter (or similar parameters) #2329
Conversation
examples/gallery/symbols/patterns.py
Outdated
The required argument has the following form: | ||
|
||
**P**\ |**p**\ *pattern*\ [**+b**\ *color*\ ][**+f**\ *color*\ ][**+r**\ *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.
I wonder if we should define a class for GMT patterns, e.g.,
class GMTPattern:
def __init__(self, id, reversed=False, bgcolor="white", fgcolor="black", dpi=1200):
...
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.
Additional to the list at the beginning of this example, there is also the possibility to add a pattern via the dcw
and frame
parameters. The syntax seems to be difficult, as it seems to be something like +g p|P resolution / pattern. The functionality seems to be limited, as it seems that no foreground and background colors could be given (please correct me if I am wrong, so far I did not figure out how to set colors here).
Example code
import pygmt
fig = pygmt.Figure()
with fig.subplot(nrows=1, ncols=2, figsize=("10c", "5c")):
with fig.set_panel(panel=0):
fig.basemap(
region=[-12, 50, 30, 70],
projection="M?",
frame="afg",
)
fig.coast(
land="lightbrown",
water="lightblue",
shorelines="1/0.5p,black",
borders="1/0.25p,red",
dcw="=EU+gp200/8", # here resolution/pattern
)
with fig.set_panel(panel=1):
fig.basemap(
region=[0, 10, 0, 10],
projection="X?",
frame=["afg", "+gp400/8"], # here resolution/pattern
)
fig.show()
# fig.savefig(fname="pattern_dcw_frame.png")
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 syntax seems to be difficult, as it seems to be something like +g p|P resolution / pattern.
This is the old syntax of patterns for GMT 4. The full old syntax is -Gpdpi/pattern[:Bcolor[Fcolor]]. I think the old syntax is still supported in GMT5 and GMT6 (backward compatibility), but it's no longer documented.
The functionality seems to be limited, as it seems that no foreground and background colors could be given.
As I understand it, it's impossible to specify foreground/background colors and dpi using the new syntax in coast -E
.
Ping @PaulWessel for comments on this.
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 wonder if we should define a class for GMT patterns, e.g.,
class GMTPattern: def __init__(self, id, reversed=False, bgcolor="white", fgcolor="black", dpi=1200): ...
Maybe we should we open a separate issue for this?
Edit 2023/03/17: Please see issue #2438.
This is surely a case where a fairly recent enhancement (specifying the fill of country via -E in coast), is stuck with a lot of other modifiers (e.g., +r) that elsewhere in -G for fills might mean different things. So here, +g is meant to set -G but we cannot easily do the full list of modifiers, unless we do some coding changes. If we just wanted to follow the pattern specs for -G then I guess we would want to use a 400 dpi red and blue pattern number 8 for Germany with
but that only gives
for the CLI. Of course, the trouble is in the C parsing since it is looking at +r to mean something with rounding of the board coordinates, not dpi of a pattern. Looking at the docs, the +f, +b are otherwise not used by -E for other things, so it may be possible to finesse something but having two different meanings of +r in the same syntax is not good. One option is to declare a bug since the +r|R main modifier prohibits us to pass a general pattern string that contains +r. We could decide that +ddpi is the required modifier and allow +f, +b, and +d if found after +g to be parsed as a pattern. We would then have to do the same to -G main pattern option and backwards introduce +d instead of +r there. You can let me know if you think this is a good solution or not. I have not looked to see how easy this is to implement (well, doing +d in -G would be simple I think), but extracting the full pattern string given to +g might need some special checking. |
Thanks a lot @seisman and @PaulWessel for these fast and detailed comments on this! |
Co-authored-by: Michael Grund <23025878+michaelgrund@users.noreply.github.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Description of proposed changes
This PR aims to add a gallery example showing how to use patterns via the
fill
parameter or similar parameters:Preview: https://pygmt-dev--2329.org.readthedocs.build/en/2329/gallery/symbols/patterns.html
References:
Fixes #2323 (partly)
The example is currently placed in the "Symbols and markers" section.
Reminders
make format
andmake check
to make sure the code follows the style guide.doc/api/index.rst
.Slash Commands
You can write slash commands (
/command
) in the first line of a comment to performspecific operations. Supported slash commands are:
/format
: automatically format and lint the code/test-gmt-dev
: run full tests on the latest GMT development version