Plot Cartesian data on projection


I have some Cartesian data on a 1 degree lat/lon grid in an xarray dataset that I want to plot using grdimage(), it has latitude, longitude and the value to be contoured, z. I want to overlay contour lines of ocean depth over the filled contours, similar to this plot (please ignore the black lines).

I’ve tried using grdproject() but the data ends up as all NaN values.

ds = xr.Dataset()
ds['z'] = (('lon', 'lat'), data)
isow_ds['lon'] = lon
isow_ds['lat'] = lat

grid = gmt.grdproject(grid=ds.z, projection=projection, region=region, spacing=(1.0, 1.0), inverse=True)

If I don’t use grdproject() and pass the dataarray to grdimage, I get the following error, even though I define the region using the same min/max lat/lon as I do to select the data.


grdimage [WARNING]: Your grid y's or latitudes appear to be outside the map region and will be skipped.
grdimage [WARNING]: No grid or image inside plot domain

I’m not sure which (if either) is the correct approach, or what to do to get this working.

Many thanks,


Hello @emmaworthington,

to overlay contour lines over the filled contours you can use Figure.grdcontour.
I think these two PyGMT examples explain what you want to do:

Thanks Yvonne, I’m probably not being clear enough. It’s the filled contours (that are unrelated to the bathymetry contours) that I’m unable to produce, grdcontour() is working fine for the bathymetry contour lines.
The data that I want filled contours for has latitude and longitude but is unrelated to the bathymetry, like the example plot where (I think) the colors represent probability. I thought that grdimage() was the correct function to use, but that causes the issues I’ve described.