# Xyz2grd and grdimage mismatch

**URL:** <https://forum.generic-mapping-tools.org/t/xyz2grd-and-grdimage-mismatch/3819>\
**Category:** PyGMT Q&A\
**Tags:** gmt\
**Created:** [April 4, 2023, 1:34pm UTC](https://forum.generic-mapping-tools.org/t/xyz2grd-and-grdimage-mismatch/3819 "2023-04-04T13:34:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gis\_sebb](https://avatars.discourse-cdn.com/v4/letter/g/278dde/32.png) [@gis\_sebb](https://forum.generic-mapping-tools.org/u/gis_sebb)\
**Post date:** [April 4, 2023, 1:34pm UTC](https://forum.generic-mapping-tools.org/t/xyz2grd-and-grdimage-mismatch/3819/1 "2023-04-04T13:34:07Z")

</div>

I have this code, where I want to use the longitude, latitude and geoidheight from my csv file.

data\_file = pd.read\_csv(“geoid\_calc\_scandinavia\_test.csv”)  
latitudes = data\_file[“latitude”]  
longitudes = data\_file[“longitude”]  
elevations = data\_file[“geoidheight”]

grid = pygmt.xyz2grd(x=longitudes,y=latitudes ,z=elevations, spacing=(0.5, 0.5), region=[-20, 40, 55, 70])

fig = pygmt.Figure()  
fig.grdimage(grid=grid)  
fig.coast(shorelines=“1/0.5p”, region=[-20, 40, 55, 70], projection=“M10i”, frame=“ag”)  
fig.show()

When i run this code, i get this image, which i cant get my head around why turn out like this:

 ![scandinavia_geoid](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/9/9887bacbe033273de1fe83c99c4e552ead6afd0b.jpeg)  
I have tried shifting x and y, latitiude and longitude, but when I do that i get this error:  
grdimage [ERROR]: Passing zmax \<= zmin prevents automatic CPT generation!  
grdimage [ERROR]: Failed to read CPT (null).

This is the file I am using:  
[CSV file](https://drive.google.com/drive/folders/1KwTRs-BlksAdXSkcsmmg86HSbzdl89ll?usp=share_link)

Anything I am misunderstanding or am I implementing it wrong? Thanks! 😀

---

<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:** [April 4, 2023, 4:10pm UTC](https://forum.generic-mapping-tools.org/t/xyz2grd-and-grdimage-mismatch/3819/2 "2023-04-04T16:10:28Z")

</div>

Hello @gis_sebb,

I think you have to specify the projection already within `pygmt.Figure.grdimage`, which is the first plotting method used for this figure. With this modification of your code, I get the output figure shown below. Does this figure match your expectation?

_Code example_:

```python
import pandas as pd
import pygmt

region_sca = [-20, 40, 55, 70]

data_file = pd.read_csv("geoid_calc_scandinavia_test.csv")
latitudes = data_file["latitude"]
longitudes = data_file["longitude"]
elevations = data_file["geoidheight"]

grid = pygmt.xyz2grd(
    x=longitudes,
    y=latitudes,
    z=elevations,
    spacing=(0.5,0.5),
    region=region_sca,
)

fig = pygmt.Figure()

fig.grdimage(
    grid=grid,
    # specify projection within the first plotting method used for this figure
    projection="M10i", 
)

fig.coast(
    shorelines="1/0.5p",
    region=region_sca,
    frame="ag",
)

# fig.colorbar()

fig.show()
# fig.savefig(fname="scandinavia_geoid.png")

```

_Output figure_:

 ![scandinavia_geoid](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/6/6f73f5fa5eddcb0043d20904a9757e6138bbef10.png)

---

<div class="post-metadata">

**Author:** ![gis\_sebb](https://avatars.discourse-cdn.com/v4/letter/g/278dde/32.png) [@gis\_sebb](https://forum.generic-mapping-tools.org/u/gis_sebb)\
**Post date:** [April 4, 2023, 9:56pm UTC](https://forum.generic-mapping-tools.org/t/xyz2grd-and-grdimage-mismatch/3819/3 "2023-04-04T21:56:50Z")

</div>

@yvonnefroehlich This was exactly what I was looking for, thanks! Appreciate it
