How to create digital elevation model from XYZ data *.txt data and module "gmt mask"

Hello I’m Rasta from Indonesia

I just learn PyGMT and try to make DEM from grided XYZ data.
I used pygmt.surface module to create DEM, instead of getting DEM like this (this image was created using fig.plot() ):

I got DEM like this :

In “basic” GMT we can use “gmt mask” to masking excess gridding data. Is this the only solution? Because i cant find this module in PyGMT. Or there is any solution to make DEM?

Thanks.

Not documented, but try doing pygmt.surface(..., M="2c", ...) to mask out areas 2 cells away from the data points. See https://docs.generic-mapping-tools.org/latest/surface.html#m