GenericMappingTools / GenericMappingTools/pygmt

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

Open
#3,764 1 comment 0 reactions 0 assignees Claimed by @Chuan1937 View on GitHub
bug
Dominant language
Python
Stars
874
Forks
255
Avg merge
1d 21h
Merged PRs (30d)
40

Description

### 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](https://github.com/user-attachments/assets/cb51aa21-23b2-4e18-8d14-8c5e6d9cec4d)

### Minimal Complete Verifiable Example

```python
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

```python-traceback
NaN.
```

### System information

```bash
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
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.