# How to not plot value zero on grid?

**URL:** <https://forum.generic-mapping-tools.org/t/how-to-not-plot-value-zero-on-grid/3783>\
**Category:** PyGMT Q&A\
**Tags:** gmt, cpt, color\
**Created:** [March 25, 2023, 7:41pm UTC](https://forum.generic-mapping-tools.org/t/how-to-not-plot-value-zero-on-grid/3783 "2023-03-25T19:41:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Feva67](https://avatars.discourse-cdn.com/v4/letter/f/51bf81/32.png) [@Feva67](https://forum.generic-mapping-tools.org/u/Feva67)\
**Post date:** [March 25, 2023, 7:41pm UTC](https://forum.generic-mapping-tools.org/t/how-to-not-plot-value-zero-on-grid/3783/1 "2023-03-25T19:41:33Z")

</div>

I have a grdimage() I want to plot on my PyGMT.Figure() with the cmap viridis, and the value zero corresponds to a yellowish color. However, the zeros on my grid represent points with no information. How can I set it so the value zero isn’t plotted, or is plotted white?

I’m very confused by it because I already managed to do it before, but can’t seem to replicate it now. I think pygmt.makecpt() doesn’t completely overwrite previous color palette tables you make, and a certain combination of colormaps implemented one after the other did the job. So if anyone knows if that’s the case, that color tables aren’t overwritten when you call pygmt.makecpt() again, and knows how to set it to be the case I would also appreciate it.

It could also be the case that an option on fig.grdimage() can let me not plot the zeros, but I haven’t found it either.

Thank you very much!

Edited for clarification 🙂

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [March 25, 2023, 8:41pm UTC](https://forum.generic-mapping-tools.org/t/how-to-not-plot-value-zero-on-grid/3783/2 "2023-03-25T20:41:25Z")

</div>

Please, respect the tags/topics.  
This is the channel for PyGMT questions, which isn’t the case of this one.

---

<div class="post-metadata">

**Author:** ![Feva67](https://avatars.discourse-cdn.com/v4/letter/f/51bf81/32.png) [@Feva67](https://forum.generic-mapping-tools.org/u/Feva67)\
**Post date:** [March 25, 2023, 10:12pm UTC](https://forum.generic-mapping-tools.org/t/how-to-not-plot-value-zero-on-grid/3783/3 "2023-03-25T22:12:05Z")

</div>

I apologize but I fail to see how this isn’t a pygmt question. I’m asking about a pygmt figure and the function pygmt.makecpt() in particular.

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [March 25, 2023, 10:26pm UTC](https://forum.generic-mapping-tools.org/t/how-to-not-plot-value-zero-on-grid/3783/4 "2023-03-25T22:26:16Z")

</div>

So sorry of me … but I still can’t see any reference to PyGMT.

> [@Feva67](#):
>
> overwritten when you call makecpt again,

not `pygmt.makecpt()`

---

<div class="post-metadata">

**Author:** ![Feva67](https://avatars.discourse-cdn.com/v4/letter/f/51bf81/32.png) [@Feva67](https://forum.generic-mapping-tools.org/u/Feva67)\
**Post date:** [March 25, 2023, 10:34pm UTC](https://forum.generic-mapping-tools.org/t/how-to-not-plot-value-zero-on-grid/3783/5 "2023-03-25T22:34:09Z")

</div>

Edited for clarification! @Joaquim

---

<div class="post-metadata">

**Author:** ![yvonnefroehlich](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/yvonnefroehlich/32/5064_2.png) [@yvonnefroehlich](https://forum.generic-mapping-tools.org/u/yvonnefroehlich)\
**Post date:** [March 26, 2023, 12:17pm UTC](https://forum.generic-mapping-tools.org/t/how-to-not-plot-value-zero-on-grid/3783/6 "2023-03-26T12:17:22Z")

</div>

Hello @Feva67,

maybe the `nan_transparent` parameter of `pygmt.Figure.grdimage` ([pygmt.Figure.grdimage — PyGMT](https://www.pygmt.org/dev/api/generated/pygmt.Figure.grdimage.html)) is useful for you? It is possible to state the z-value which is plotted as transparent (Default is NaN). Therefore, you have to use **+z** _value_. This is currently only documented in the upstream GMT documentation at [grdimage — GMT 6.7.0 documentation](https://docs.generic-mapping-tools.org/dev/grdimage.html#q).

Below, you find a code example, which may serve as an orientation. However, for a more detailed help, please share your code with us. This will make it significantly easier for others to help you 🙂.

_Example code_:

```python
import pygmt

# Load sample grid dataset
grid_relief = pygmt.datasets.load_earth_relief()

# Create figure object
fig = pygmt.Figure()

fig.basemap(
    region=[0, 360, -90, 90], # lon_min, lon_max, lat_min, lat_max
    projection="H15c", # Hammer projection with a width of 15 centimeters
    frame=True,
)
# Set up colormap
pygmt.makecpt(
    cmap="viridis",
    series=[-8500, 6000, 100], # min, max], step
)
# Plot colored grid
fig.grdimage(
    grid=grid_relief,
    cmap=True,
    # https://www.pygmt.org/dev/api/generated/pygmt.Figure.grdimage.html
    # https://docs.generic-mapping-tools.org/dev/grdimage.html#q
    # make z-values = 0 transparent
    # change the value after "+z" to the z-value you want appear transparent
    nan_transparent="+z0",
)

fig.colorbar(frame="+lelevation in m")

fig.show()
# fig.savefig("grdimage_nan_transparent.png")

```

_Output figure_:

 ![grdimage_nan_transparent](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/8/81150c6adc65ba55ef4279f6d77ba56b49366b6d.png)

---

<div class="post-metadata">

**Author:** ![Feva67](https://avatars.discourse-cdn.com/v4/letter/f/51bf81/32.png) [@Feva67](https://forum.generic-mapping-tools.org/u/Feva67)\
**Post date:** [March 27, 2023, 3:17pm UTC](https://forum.generic-mapping-tools.org/t/how-to-not-plot-value-zero-on-grid/3783/7 "2023-03-27T15:17:57Z")

</div>

Thank you so very much @yvonnefroehlich! This is exactly what I needed.

I’m left to wonder about the fact of CPTs not being overwritten, maybe I’ll try to make a simple example and post it later.
