# How to create grid and mask NaN areas with gray color

**URL:** <https://forum.generic-mapping-tools.org/t/how-to-create-grid-and-mask-nan-areas-with-gray-color/1577>\
**Category:** Q&A\
**Created:** [April 16, 2021, 3:47pm UTC](https://forum.generic-mapping-tools.org/t/how-to-create-grid-and-mask-nan-areas-with-gray-color/1577 "2021-04-16T15:47:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![John](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/john/32/40_2.png) [@John](https://forum.generic-mapping-tools.org/u/John)\
**Post date:** [April 16, 2021, 3:47pm UTC](https://forum.generic-mapping-tools.org/t/how-to-create-grid-and-mask-nan-areas-with-gray-color/1577/1 "2021-04-16T15:47:04Z")

</div>

Hello, Please I need help to convert my data file xyz to grid with grid points NaN masked and output in gray color similar to this figure below. Many thanks.

 ![image](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/2/2b15984d27fb401778dbab9beec9c5d74d54618d.jpeg)

---

<div class="post-metadata">

**Author:** ![maxrjones](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/maxrjones/32/2698_2.png) [@maxrjones](https://forum.generic-mapping-tools.org/u/maxrjones)\
**Post date:** [April 17, 2021, 2:03am UTC](https://forum.generic-mapping-tools.org/t/how-to-create-grid-and-mask-nan-areas-with-gray-color/1577/2 "2021-04-17T02:03:45Z")

</div>

Hi John,

Here are the GMT modules that can help with your task:

1. xyz2grd can be used to create a grid from xyz points: [https://docs.generic-mapping-tools.org/latest/xyz2grd.html](https://docs.generic-mapping-tools.org/latest/xyz2grd.html)
2. makecpt can be used to make a color palette for your data: [https://docs.generic-mapping-tools.org/latest/makecpt.html](https://docs.generic-mapping-tools.org/latest/makecpt.html). Specifically, take a look at the -M option to use COLOR\_NAN for the color of NaN values (see [https://docs.generic-mapping-tools.org/latest/gmtset.html](https://docs.generic-mapping-tools.org/latest/gmtset.html) for how to set COLOR\_NAN).
3. grdimage can be used to grid the data: [https://docs.generic-mapping-tools.org/latest/grdimage.html](https://docs.generic-mapping-tools.org/latest/grdimage.html)
4. colorbar can be used to make the colorbar: [https://docs.generic-mapping-tools.org/latest/colorbar.html](https://docs.generic-mapping-tools.org/latest/colorbar.html)

In addition to the examples at the end of these pages, the general examples page provides some useful examples of these commands in use: [https://docs.generic-mapping-tools.org/latest/gallery.html](https://docs.generic-mapping-tools.org/latest/gallery.html).

Hope this helps!

---

<div class="post-metadata">

**Author:** ![John](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/john/32/40_2.png) [@John](https://forum.generic-mapping-tools.org/u/John)\
**Post date:** [April 17, 2021, 9:15am UTC](https://forum.generic-mapping-tools.org/t/how-to-create-grid-and-mask-nan-areas-with-gray-color/1577/3 "2021-04-17T09:15:11Z")

</div>

Many thanks Sir/Ma, however, xyz2grd will interpolate the data, hence the NaN points will be overlapped after the grid has been generated with xyz2grd. I have tried this

---

<div class="post-metadata">

**Author:** ![John](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/john/32/40_2.png) [@John](https://forum.generic-mapping-tools.org/u/John)\
**Post date:** [April 17, 2021, 9:18am UTC](https://forum.generic-mapping-tools.org/t/how-to-create-grid-and-mask-nan-areas-with-gray-color/1577/4 "2021-04-17T09:18:28Z")

</div>

from the photo I shared the NaN grid points are colored in gray representing no data points. while others with data are shown with colors. All I want to do is just to plot my data and how the NaN points to be shown as gray color on my map. Thanks.

---

<div class="post-metadata">

**Author:** ![Esteban82](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/esteban82/32/54_2.png) [@Esteban82](https://forum.generic-mapping-tools.org/u/Esteban82)\
**Post date:** [April 18, 2021, 3:53am UTC](https://forum.generic-mapping-tools.org/t/how-to-create-grid-and-mask-nan-areas-with-gray-color/1577/5 "2021-04-18T03:53:29Z")

</div>

Do you try an smaller value for the increment ( xyz2grd -I)?

---

<div class="post-metadata">

**Author:** ![John](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/john/32/40_2.png) [@John](https://forum.generic-mapping-tools.org/u/John)\
**Post date:** [April 19, 2021, 2:42pm UTC](https://forum.generic-mapping-tools.org/t/how-to-create-grid-and-mask-nan-areas-with-gray-color/1577/6 "2021-04-19T14:42:00Z")

</div>

many thanks, I got it done with grdclip.
