# Pygmt.grdimage not plotting data

**URL:** <https://forum.generic-mapping-tools.org/t/pygmt-grdimage-not-plotting-data/5693>\
**Category:** PyGMT Q&A\
**Created:** [January 23, 2025, 3:06am UTC](https://forum.generic-mapping-tools.org/t/pygmt-grdimage-not-plotting-data/5693 "2025-01-23T03:06:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dpath2o](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/dpath2o/32/1732_2.png) [@dpath2o](https://forum.generic-mapping-tools.org/u/dpath2o)\
**Post date:** [January 23, 2025, 3:06am UTC](https://forum.generic-mapping-tools.org/t/pygmt-grdimage-not-plotting-data/5693/1 "2025-01-23T03:06:07Z")

</div>

Attempting to perform simple gridded image plot using pygmt.grdimage .

I know this is some issue with my understanding so this is not a bug report, and hopefully it is easy enough for a someone to quickly see the solution.

Here is the data:  
\<xarray.DataArray (y: 185, x: 148)\> Size: 110kB  
array([[nan, nan, nan, …, nan, nan, nan],  
[nan, nan, nan, …, nan, nan, nan],  
[nan, nan, nan, …, nan, nan, nan],  
…,  
[nan, nan, nan, …, nan, nan, nan],  
[nan, nan, nan, …, nan, nan, nan],  
[nan, nan, nan, …, nan, nan, nan]], dtype=float32)  
Coordinates:  
lon (y, x) float32 110kB -18.88 -18.62 -18.38 … 17.38 17.62 17.88  
lat (y, x) float32 110kB -79.92 -79.92 -79.92 … -60.08 -60.08 -60.08  
Dimensions without coordinates: y, x  
Attributes:  
description: Fast ice thickness  
units: m

This is code that I used to create the xarray data array.

```auto
        hi_plt = xr.DataArray(data=hi_mask.values,
                              dims=["y", "x"],
                              coords=dict(lon=(["y", "x"], lon_mask.values),
                                          lat=(["y", "x"], lat_mask.values)),
                              attrs=dict(description="Fast ice thickness",
                                         units="m"))

```

This is code that I’m using to attempt to visualise this data:

```auto
        proj = f"B{lonC:.1f}/{latC:.1f}/{ext_plt[2]:.1f}/{ext_plt[3]:.1f}/20c"
        pygmt.makecpt(cmap="cmocean/amp", series=[0,5], output="hi_mask.cpt")
        fig = pygmt.Figure()
        fig.grdimage(grid=hi_plt, cmap="hi_mask.cpt", projection=proj, region=ext_plt, frame="a")
        fig.coast(land="white", water="black")
        fig.colorbar(cmap="hi_mask.cpt",
                     frame="a1f.5+lThickness (m)",
                     position="JBC+w10c/0.4c+mc+h")
        fig.show()

```

And this is the warning that it results in:

> 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 also attached the xarray simple visualisation of the data that I’m attempting to reprsent geographically with pygmt.

Thanks for your help.

 ![Unknown-1](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/f/feb4f94cdf0fc0957e3d9093da518542363c847d.png)  
 ![Unknown](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/0/0054cb8cc164090a1e36747caf62b79514c81605.png)

---

<div class="post-metadata">

**Author:** ![dpath2o](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/dpath2o/32/1732_2.png) [@dpath2o](https://forum.generic-mapping-tools.org/u/dpath2o)\
**Post date:** [January 23, 2025, 5:06am UTC](https://forum.generic-mapping-tools.org/t/pygmt-grdimage-not-plotting-data/5693/2 "2025-01-23T05:06:38Z")

</div>

Solved my own issue.

```auto
        hi_grd = pygmt.nearneighbor(x=np.ravel(lon_mask.values),
                                    y=np.ravel(lat_mask.values),
                                    z=np.ravel(hi_mask.values),
                                    region=ext_plt,
                                    spacing="15m",
                                    search_radius="20m")
        aice_grd = pygmt.nearneighbor(x=np.ravel(lon_mask.values),
                                      y=np.ravel(lat_mask.values),
                                      z=np.ravel(aice_mask.values),
                                      region=ext_plt,
                                      spacing="15m",
                                      search_radius="20m")
        proj = f"B{lonC:.1f}/{latC:.1f}/{ext_plt[2]:.1f}/{ext_plt[3]:.1f}/20c"
        fig = pygmt.Figure()
        fig.coast(projection=proj, region=ext_plt, land="white", water="black", frame="a")
        pygmt.makecpt(cmap="cmocean/ice", series=[0,1])
        fig.grdimage(grid=aice_grd, cmap=True, nan_transparent=True)#, projection=proj, region=ext_plt)
        fig.colorbar(frame=["x+lPack ice concentration", "y+l1/100"], position="JMR+o0.5c/0c+w10c")
        pygmt.makecpt(cmap="cmocean/amp", series=[0,5])
        fig.grdimage(grid=hi_grd, cmap=True, nan_transparent=True)#, projection=proj, region=ext_plt)
        fig.colorbar(frame="a1f.5+lFast ice thickness (m)", position="JBC+w10c/0.5c+mc+h")
        fig.show()
        fig.savefig(P_save)

```

 ![Unknown-3](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/a/a420a5a24471e530930936fab8fed6996fa13373.png)
