Skip to content

Conversation

@seisman
Copy link
Member

@seisman seisman commented Dec 23, 2024

This PR adds an image for comparing GMT and PyGMT syntax. The script is adapted from https://www.pygmt.org/dev/install.html#testing-your-install.

Fig1_PyGMT_GMT_comparison

TODO:

@gitnotebooks
Copy link

gitnotebooks bot commented Dec 23, 2024

Found 1 changed notebook. Review the changes at https://app.gitnotebooks.com/GenericMappingTools/pygmt-paper-figures/pull/4

@seisman seisman marked this pull request as ready for review November 7, 2025 02:59
@seisman
Copy link
Member Author

seisman commented Nov 10, 2025

@yvonnefroehlich @weiji14 Any comments on this example?

@weiji14
Copy link
Member

weiji14 commented Nov 10, 2025

Debating on whether to keep the text the same for both, e.g. use something like text="ABCD", just to make the comparison more exact. Other than that, I think it's a fine example.

@seisman
Copy link
Member Author

seisman commented Nov 10, 2025

If the same text is prefered, we can use "GMT" in both.

@seisman
Copy link
Member Author

seisman commented Nov 11, 2025

If the same text is prefered, we can use "GMT" in both.

I've updated the example to use the same text "GMT" in both versions.

@yvonnefroehlich
Copy link
Member

image

It looks like the "@" within red@75 is not included in the plotted text, event it is containted in the related strings.

@yvonnefroehlich
Copy link
Member

yvonnefroehlich commented Nov 20, 2025

I am wondering if we want to color the coresponding parts in the codes for GMT and PyGMT in the same colors; similar as we did it in the presentation for AGU last year; e.g., (colors can be discussed and adjusted):

Fig1_PyGMT_GMT_comparison_color_atsign
Click for codes (but using `Figure.text` with a loop and `@@` for the @ sign in GMT):

import pygmt


# Sequence of strings for the GMT CLI code.
# The leading tab characters are intentional to match the indentation.
gmt_str = """


gmt begin GMT_map png
\tgmt @;gray50;basemap@;; @;blue;-JN15c@;; @;purple;-R0/360/-90/90@;; @;orange;-B@;;
\tgmt @;gray50;coast@;; @;tan;-Gtan@;; @;lightblue;-Slightblue@;;
\t@;magenta;echo GMT@;; | gmt @;gray50;text@;; @;red;-F+f80p,Helvetica-Bold,red@@75@;;@;brown;+cMC@;;
gmt end @;gray50;show@;;
""".splitlines()

# Sequence of strings for the PyGMT code.
pygmt_str = """
import pygmt

fig = pygmt.Figure()
fig.@;gray50;basemap@;;(@;blue;projection="N15c"@;;, @;purple;region=[0, 360, -90, 90]@;;, @;orange;frame=True@;;)
fig.@;gray50;coast@;;(@;tan;land="tan"@;;, @;lightblue;water="lightblue"@;;)
fig.@;gray50;text@;;(@;brown;position="MC"@;;, @;magenta;text="GMT"@;;, @;red;font="80p,Helvetica-Bold,red@@75@;;")
fig.@;gray50;show@;;()
fig.@;gray50;savefig@;;("PyGMT_map.png")
""".splitlines()

args_text = {"x": 0.25, "justify": "BL", "font": "Courier-Bold,6p"}


fig = pygmt.Figure()
pygmt.config(FONT_TITLE="10p", MAP_TITLE_OFFSET="4p")

fig.basemap(region=[0, 20, 0, 3], projection="X7.1/2c", frame="lrtb+tGMT CLI")
y = 3
for i in range(len(gmt_str)):
    fig.text(text=gmt_str[i], y=y, **args_text)
    y = y - 0.35

fig.shift_origin(xshift="w+0.1c")

fig.basemap(region=[0, 20, 0, 3], projection="X9/2c", frame="lrtb+tPyGMT")
y = 3
for i in range(len(pygmt_str)):
    fig.text(text=pygmt_str[i], y=y, **args_text)
    y = y - 0.35

fig.show()
fig.savefig("Fig1_PyGMT_GMT_comparison_color_atsign.png")

@seisman
Copy link
Member Author

seisman commented Nov 20, 2025

image It looks like the "@" within `red@75` is not included in the plotted text, event it is containted in the related strings.

Nice catch. Need to use @@ when typesetting text strings.

@seisman
Copy link
Member Author

seisman commented Nov 21, 2025

I am wondering if we want to color the coresponding parts in the codes for GMT and PyGMT in the same colors; similar as we did it in the presentation for AGU last year; e.g., (colors can be discussed and adjusted):

Fig1_PyGMT_GMT_comparison_color_atsign

I feel it makes the code a little too complicated. Unlike presentations, people usually have more time to read and compare the codes in the manuscript.

seisman and others added 2 commits November 21, 2025 21:47
@yvonnefroehlich
Copy link
Member

yvonnefroehlich commented Nov 21, 2025

I am wondering if we want to color the coresponding parts in the codes for GMT and PyGMT in the same colors; similar as we did it in the presentation for AGU last year; e.g., (colors can be discussed and adjusted):

I feel it makes the code a little too complicated. Unlike presentations, people usually have more time to read and compare the codes in the manuscript.

Agree, the text strings get long and difficult to read with all the in-text color changes.

@seisman
Copy link
Member Author

seisman commented Nov 27, 2025

Perhaps we should merge these approved examples into the main branch? When new changes are needed, we can just open a separate PR so that we can focus on the changes.

@seisman seisman merged commit 203d079 into main Nov 27, 2025
1 check passed
@seisman seisman deleted the fig1/pygmt-gmt-comparison branch November 27, 2025 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants