Skip to content
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

Colorbar positioning is problematic in subplot mode #2426

Closed
seisman opened this issue Mar 15, 2023 · 4 comments
Closed

Colorbar positioning is problematic in subplot mode #2426

seisman opened this issue Mar 15, 2023 · 4 comments
Labels
bug Something isn't working
Milestone

Comments

@seisman
Copy link
Member

seisman commented Mar 15, 2023

Initially found in #2354 (comment).

Here is a minimal example to reproduce the issue:

import pygmt
fig = pygmt.Figure()
with fig.subplot(nrows=1, ncols=2, figsize=(10, 5)):
    fig.basemap(region=[0, 10, 0, 10], projection="X?", frame=True, panel=True)
    fig.basemap(region=[0, 10, 0, 10], projection="X?", frame=True, panel=True)
fig.colorbar(position="JBC+w5c+h", cmap="turbo", frame=True)
fig.show()

The "equivalent" GMT bash script is:

gmt begin
    gmt figure map
	gmt subplot begin 1x2 -Ff10c/5c
		gmt basemap -R0/10/0/10 -JX? -B -c
		gmt basemap -R0/10/0/10 -JX? -B -c
	gmt subplot end
	gmt colorbar -DJBC+w5c+h -Cturbo -B
gmt end show

PyGMT and GMT CLI produce different outputs, and the GMT CLI one is correct:

PyGMT GMT CLI
pygmt-colorbar bash-colorbar
@seisman
Copy link
Member Author

seisman commented Mar 15, 2023

After adding verbose="d" to the Figure.colobar() call in the PyGMT script, I see debug messages like:

pygmt-session [DEBUG]: Use PS filename /Users/seisman/.gmt/sessions/gmt_session.6653/gmt_1.ps-
pygmt-session [DEBUG]: gmtinit_get_current_panel: No current panel selected so not in subplot mode
pygmt-session [DEBUG]: Modern mode: Added -R to options since history is available [0/3.93701/0/1.9685].
pygmt-session [DEBUG]: Modern: Adding -JX15c/15c to options since there is no history available.
pygmt-session [DEBUG]: Revised options: -B -Cturbo -DJBC+w5c+h -Vd -R -JX15c/15c
colorbar [DEBUG]: History: Process -R
colorbar [DEBUG]: History: Process -JX15c/15c

For comparison, adding -Vd to the colorbar command in the bash script gives:

gmt [DEBUG]: Use PS filename /Users/seisman/.gmt/sessions/gmt_session.6943/gmt_0.ps-
gmt [DEBUG]: gmtinit_get_current_panel: No current panel selected so not in subplot mode
gmt [DEBUG]: Modern mode: Added -R to options since history is available [0/3.93701/0/1.9685].
gmt [DEBUG]: Modern: Adding -J to options since history is available [x1i].
gmt [DEBUG]: Revised options: -DJBC+w5c+h -Cturbo -B -Vd -R -J
colorbar [DEBUG]: History: Process -R
colorbar [DEBUG]: History: Process -J

So, for unknown reasons, PyGMT fails to get the history information for -J option and use the default -JX15c/15c instead, which explains the incorrect positioning of colorbars.

@seisman
Copy link
Member Author

seisman commented Mar 15, 2023

Ping @PaulWessel. Need your help here.

@PaulWessel
Copy link
Member

PaulWessel commented Mar 15, 2023

Hm, got to be something different in the wrapper when it calls GMT compared to the CLI. I suggest you first do this

  1. gmt clear sessions
  2. Run each of the CLI commands and examine what is created in ~/.gmt/sessions/gmt_session.* Take a note of files being created and destroyed after each command
  3. Repeat 1
  4. Do the same on command at the time via PyGMT and compare to see what and when things go wrong.

@seisman
Copy link
Member Author

seisman commented Mar 15, 2023

Hm, got to be something different in the wrapper when it calls GMT compared to the CLI. I suggest you first do this

  1. gmt clear sessions
  2. Run each of the CLI commands and examine what is created in ~/.gmt/sessions/gmt_session.* Take a note of files being created and destroyed after each command
  3. Repeat 1
  4. Do the same on command at the time via PyGMT and compare to see what and when things go wrong.

Thanks. It helps me find the culprit. It's NOT a GMT bug. It's a bug on the PyGMT side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants