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

"fig.region" is not updated to the "region" of the current plot | Wrong lines via hlines and vlines #3764

Open
yvonnefroehlich opened this issue Jan 10, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@yvonnefroehlich
Copy link
Member

Description of the problem

To get the region of the a PyGMT Figure, fig.region can be used. In case a figure contains different plots with different regions, fig.region always provides the region related to the first plot. This affects the hlines and vlines methods. By default, a line is plotted extending over the complete plotting region. This leads to unexpected / wrong lines for the second and following plots, as the region values related to the first plot are used. A workaround is to explicitly specify the limits.

Image

Minimal Complete Verifiable Example

import pygmt

fig = pygmt.Figure()

fig.basemap(region=[-1, 1, -1, 1], projection="X4c", frame=1)
print(fig.region)  # [-1.  1. -1.  1.]
fig.hlines(y=0)
fig.vlines(x=0)

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

fig.basemap(region=[-2, 2, -2, 2], projection="X4c", frame=1)
print(fig.region)  # still [-1.  1. -1.  1.]
fig.hlines(y=0)
fig.vlines(x=0)

fig.show()

Full error message

NaN.

System information

PyGMT information:
  version: v0.14.1.dev10
System information:
  python: 3.12.3 | packaged by conda-forge | (main, Apr 15 2024, 18:20:11) [MSC v.1938 64 bit (AMD64)]
  executable: C:\ProgramData\Anaconda3\envs\pygmt_env_dev_650\python.exe
  machine: Windows-10-10.0.19045-SP0
Dependency information:
  numpy: 1.26.4
  pandas: 2.2.0rc0
  xarray: 2024.3.0
  netCDF4: 1.6.5
  packaging: 24.0
  contextily: 1.6.0
  geopandas: 0.14.3
  IPython: 8.22.2
  pyarrow: None
  rioxarray: 0.15.4
  gdal: 3.8.2
  ghostscript: 10.03.0
GMT library information:
  version: 6.5.0
  padding: 2
  share dir: C:/Program Files (x86)/gmt6/share
  plugin dir: C:/ProgramData/Anaconda3/envs/pygmt_env_dev_650/Library/bin/gmt_plugins
  library path: C:/ProgramData/Anaconda3/envs/pygmt_env_dev_650/Library/bin/gmt.dll
  cores: 4
  grid layout: rows
  image layout: 
  binary version: 6.5.0
@yvonnefroehlich yvonnefroehlich added the bug Something isn't working label Jan 10, 2025
@seisman
Copy link
Member

seisman commented Jan 11, 2025

I can confirm the bug. Figure.region calls the Session.extract_region method, which wraps the GMT_Extract_Region API function.

The GMT_Extract_Region API function opens the "hidden" PS file and reads the information from lines with the PROJ tag, so it can only find the first "region".

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