Repository navigation
Open
Labels
bugSomething isn't working
Description
Description of the problem
I am attempting to draw a contour which encompasses the south pole using grdcontour. Everything works fine when passing a netcdf filename, but when passing an xarray DataArray, the points at the far left and right of the plot are connected by a straight line.
Here is the image using a DataArray

And here is the image using the netcdf file

I note that the second image generates a warning (as shown below), but it works nonetheless.
Minimal Complete Verifiable Example
# create a dummy dataset
interval = 0.2
lat = np.arange(90, -90 - interval, -interval)
lon = np.arange(0, 360 + interval, interval)
longrid, latgrid = np.meshgrid(lon, lat)
data = 0.2 * np.cos(np.deg2rad(longrid)) + np.sin(np.deg2rad(latgrid))
grid = xr.DataArray(data, coords=[("latitude", lat), ("longitude", lon)])
grid.gmt.registration = 0
grid.gmt.gtype = 1
grid.to_netcdf('grid.nc')
# plot and use grdcontour with the dataarray
fig = pygmt.Figure()
fig.grdimage(grid, projection='W0/10c')
fig.grdcontour(grid, levels='-0.9,')
fig.show()
fig.savefig('grid1.png')
# Do the same using the netcdf file
fig2 = pygmt.Figure()
fig2.grdimage('grid.nc', projection='W0/10c')
fig2.grdcontour('grid.nc', levels='-0.9,')
fig2.show()
fig2.savefig('grid2.png')Full error message
grdimage [WARNING]: Guessing of registration in conflict between x and y, using gridline
grdcontour [WARNING]: Guessing of registration in conflict between x and y, using gridlineSystem information
PyGMT information:
version: v0.13.0
System information:
python: 3.12.5 | packaged by conda-forge | (main, Aug 8 2024, 18:36:51) [GCC 12.4.0]
executable: /home/mrak/miniforge3/envs/py312/bin/python
machine: Linux-6.10.10-200.fc40.x86_64-x86_64-with-glibc2.39
Dependency information:
numpy: 2.1.0
pandas: 2.2.2
xarray: 2024.7.0
netCDF4: 1.7.1
packaging: 24.1
contextily: None
geopandas: None
IPython: 8.26.0
rioxarray: None
gdal: 3.9.2
ghostscript: 10.03.1
GMT library information:
version: 6.5.0
padding: 2
share dir: /home/mrak/miniforge3/envs/py312/share/gmt
plugin dir: /home/mrak/miniforge3/envs/py312/lib/gmt/plugins
library path: /home/mrak/miniforge3/envs/py312/lib/libgmt.so
cores: 20
grid layout: rows
image layout:
binary version: 6.5.0Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
leouieda commentedon Sep 5, 2025
Just reporting here that I had the same issue with contours wrapping around in a straight line. I think this may have something to do with loss of some metadata when we pass the grid as a DataArray but I'm not sure.
yousizaitianqiong commentedon Nov 21, 2026
I reproduced the extra line by calling the GMT C API directly on GMT master (
97962cf3, version 6.8.0). I used a 1° global grid with geographic coordinates and gridline registration explicitly set. With a Mollweide projection centered at 0° and the-0.9contour, the0°–360°grid passed asGMT_VIA_MATRIXproduced the long line. A NetCDF file and aGMT_GRIDvirtual file produced identical plots. Aligning the matrix longitudes to-180°–180°also removed the long line in this example. The column with the most contour pixels contained 959 pixels for the unaligned matrix and 116 for each of the three controls.GMT detects the seam crossing in this case. Rounding in a projected coordinate can reverse the order of the two boundary intersections and draw a segment across the map. A GMT-side candidate uses the crossing direction when ordering the intersections and preserves it through latitude clipping. The unaligned matrix measures 116 pixels in the local rerun, and cropped Mollweide and Hammer cases also pass their drawing comparisons. Further validation is in progress.