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.
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:
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()
This is 100% what I was looking for, thank you.