# PyGMT: Coloring pixels of a specific elevation

**URL:** <https://forum.generic-mapping-tools.org/t/pygmt-coloring-pixels-of-a-specific-elevation/1897>\
**Category:** PyGMT Q&A\
**Created:** [July 15, 2021, 8:56pm UTC](https://forum.generic-mapping-tools.org/t/pygmt-coloring-pixels-of-a-specific-elevation/1897 "2021-07-15T20:56:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hazardgoat](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/hazardgoat/32/1354_2.png) [@hazardgoat](https://forum.generic-mapping-tools.org/u/hazardgoat)\
**Post date:** [July 15, 2021, 8:56pm UTC](https://forum.generic-mapping-tools.org/t/pygmt-coloring-pixels-of-a-specific-elevation/1897/1 "2021-07-15T20:56:45Z")

</div>

With PyGMT, is there a way to color the pixels of a raster at a specific elevation with cmap? I’d like to, say, color only the 50m elevation pixels.

---

<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:** [July 20, 2021, 12:32am UTC](https://forum.generic-mapping-tools.org/t/pygmt-coloring-pixels-of-a-specific-elevation/1897/2 "2021-07-20T00:32:25Z")

</div>

I am not sure if this is the best solution, but I would probably just clip the grip to only include values equal 50 for plotting. Here is an example:

```auto
import numpy as np
import pygmt
import xarray as xr

# Define a function of two variables
def sumgrid(x, y):
    return (
        x + y
    )

# Create gridded data
INC = 0.2
x = np.arange(0, 50 + INC, INC)
y = np.arange(0, 50 + INC, INC)
data = xr.DataArray(sumgrid(*np.meshgrid(x, y)), coords=(x, y))
data_clip = pygmt.grdclip(grid=data, above="50/NaN", below="50/NaN")

fig = pygmt.Figure()
# Plot grid
fig.grdimage(
    grid=data,
    projection="X10c",
    region=[0,50,0,50],
    frame=True,
    cmap="gray"
)
pygmt.makecpt(cmap="hot", series=[45,55,10])
fig.grdimage(
    grid=data_clip,
    cmap=True,
    nan_transparent=True
)

fig.show()

```

---

<div class="post-metadata">

**Author:** ![hazardgoat](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/hazardgoat/32/1354_2.png) [@hazardgoat](https://forum.generic-mapping-tools.org/u/hazardgoat)\
**Post date:** [July 26, 2021, 5:54pm UTC](https://forum.generic-mapping-tools.org/t/pygmt-coloring-pixels-of-a-specific-elevation/1897/3 "2021-07-26T17:54:51Z")

</div>

This is 100% what I was looking for, thank you.
