# Grid point to surface

**URL:** <https://forum.generic-mapping-tools.org/t/grid-point-to-surface/3422>\
**Category:** PyGMT Q&A\
**Created:** [November 8, 2022, 4:41pm UTC](https://forum.generic-mapping-tools.org/t/grid-point-to-surface/3422 "2022-11-08T16:41:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mtabbakhha](https://avatars.discourse-cdn.com/v4/letter/m/c68b51/32.png) [@mtabbakhha](https://forum.generic-mapping-tools.org/u/mtabbakhha)\
**Post date:** [November 8, 2022, 4:41pm UTC](https://forum.generic-mapping-tools.org/t/grid-point-to-surface/3422/1 "2022-11-08T16:41:27Z")

</div>

Hi Guys. I used grid command to make some grid point to show my data on a map.  
df = pygmt.blockmean(data=data, region=[-122.8, -121.4, 37.0, 38.4], spacing=spacing)

# convert to grid

#grid = pygmt.surface(data=df, region=region, spacing=spacing)  
grid = pygmt.xyz2grd(data=df, region=[-122.8, -121.4, 37.0, 38.4], spacing=spacing, registration=“p”)

Grid spacing is 01s which I guess is the lowest but the problem is that the data are shown as a point. I want to hame a uniform surface. How can I have the surface not point from grdimage?

fig.grdimage(  
grid=grid,  
region=[-123, -121, 37, 38.5],  
#transparency=50,  
cmap=True,  
nan\_transparent=True,  
frame=[“af”, “+tMean earthquake depth inside each block”],

# cmap=“batlow”,

)

---

<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:** [November 8, 2022, 5:22pm UTC](https://forum.generic-mapping-tools.org/t/grid-point-to-surface/3422/2 "2022-11-08T17:22:55Z")

</div>

Please, format your code with triple back-ticks.

---

<div class="post-metadata">

**Author:** ![mtabbakhha](https://avatars.discourse-cdn.com/v4/letter/m/c68b51/32.png) [@mtabbakhha](https://forum.generic-mapping-tools.org/u/mtabbakhha)\
**Post date:** [November 8, 2022, 5:58pm UTC](https://forum.generic-mapping-tools.org/t/grid-point-to-surface/3422/3 "2022-11-08T17:58:01Z")

</div>

![Screen Shot 2022-11-08 at 9.57.08 AM](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/f/f43ae17afc45e7a0c17673e71350b9c9fcca80a3.jpeg) [quote=“mtabbakhha, post:1, topic:3422”]  
cmap=“batlow”,  
[/quote]

it still doesn’t work. I just see the points not any surface. You see the point? I wanted to be a continues not just the points.

Thanks so much for your help.

---

<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:** [November 8, 2022, 6:32pm UTC](https://forum.generic-mapping-tools.org/t/grid-point-to-surface/3422/4 "2022-11-08T18:32:30Z")

</div>

I meant, format your code when you post it.

```auto
df = pygmt.blockmean(data=data, region=[-122.8, -121.4, 37.0, 38.4], spacing=spacing)
# convert to grid
#grid = pygmt.surface(data=df, region=region, spacing=spacing)
grid = pygmt.xyz2grd(data=df, region=[-122.8, -121.4, 37.0, 38.4], spacing=spacing, registration="p")

Grid spacing is 01s which I guess is the lowest but the problem is that the data are shown as a point. I want to hame a uniform surface. How can I have the surface not point from grdimage?

fig.grdimage(
    grid=grid,
    region=[-123, -121, 37, 38.5],
#transparency=50,
    cmap=True,
    nan_transparent=True,
    frame=["af", "+tMean earthquake depth inside each block"],
  # cmap="batlow",
)

```

But regarding your question, sorry, I don’t _PyGMT_.

---

<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:** [November 9, 2022, 4:17pm UTC](https://forum.generic-mapping-tools.org/t/grid-point-to-surface/3422/5 "2022-11-09T16:17:27Z")

</div>

Hello @mtabbakhha,

I am wondering whether `pygmt.blockmean` is the appropriate function for your purpose.  
It sounds like you want to interpolate your data somehow? But I am not sure, as your posted figure already contains a grid with color-coding for the elevation in your study region. Plotting another color-coded grid on top appears not reasonable to me. Maybe you can explain in more detail what you want to accomplish 😉.

`pygmt.blockmean` calculates the mean within blocks/bins with side lengths defined by the `spacing` parameter. For details, please have a look at the documentation [pygmt.blockmean — PyGMT](https://www.pygmt.org/latest/api/generated/pygmt.blockmean.html#pygmt.blockmean).  
If you select a small value for the `spacing` parameter (“01s”), the blocks plotted by `pygmt.Figure.grdimage` are also small.

Please see a PyGMT gallery example for orientation, in which I modified the `spacing` parameter:

```auto
# source: https://www.pygmt.org/latest/gallery/histograms/blockm.html#sphx-glr-gallery-histograms-blockm-py
# last access: 2022/11/09
# modified: only left plot, changed spacing parameter

import pygmt

# Load sample data
data = pygmt.datasets.load_sample_data(name="japan_quakes")
# Select only needed columns
data = data[["longitude", "latitude", "depth_km"]]

# Set the region for the plot
region = [130, 152.5, 32.5, 52.5]
# Define spacing in x and y direction (150 by 150 minute blocks)
spacing = "100m" # <<< original "150m"

fig = pygmt.Figure()

# Calculate mean depth in km from all events within 150x150 minute
# bins using blockmean
df = pygmt.blockmean(data=data, region=region, spacing=spacing)
# convert to grid
grd = pygmt.xyz2grd(data=df, region=region, spacing=spacing)

fig.grdimage(
    grid=grd,
    region=region,
    frame=["af", "+tMean earthquake depth inside each block"],
    cmap="batlow",
)
# plot slightly transparent landmasses on top
fig.coast(land="darkgray", transparency=40)
# plot original data points
fig.plot(
    x=data.longitude,
    y=data.latitude,
    style="c0.3c",
    color="white",
    pen="1p,black",
)
fig.colorbar(frame="x+lkm")

fig.show()
#fig.savefig(fname="block_mean_spacing_" + spacing + ".png")

```

output figures:  
**original: spacing=“150m”**

 ![block_mean_spacing_150m](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/2/218458ea80ed60aaed7e1a557c4d9c9caa26ce96.png)

**modified: spacing=“100m”**

 ![block_mean_spacing_100m](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/d/d832dc465b8eeb8afb28fdbce84f24389bb89922.png)

**modified: spacing=“50m”**

 ![block_mean_spacing_50m](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/8/84d6b967ff7802a2b58cb22bd280a4b44c3463ba.png)
