# How to plot temperature?

**URL:** <https://forum.generic-mapping-tools.org/t/how-to-plot-temperature/1760>\
**Category:** PyGMT Q&A\
**Created:** [June 7, 2021, 7:39pm UTC](https://forum.generic-mapping-tools.org/t/how-to-plot-temperature/1760 "2021-06-07T19:39:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ljeonjko](https://avatars.discourse-cdn.com/v4/letter/l/b5ac83/32.png) [@ljeonjko](https://forum.generic-mapping-tools.org/u/ljeonjko)\
**Post date:** [June 7, 2021, 7:39pm UTC](https://forum.generic-mapping-tools.org/t/how-to-plot-temperature/1760/1 "2021-06-07T19:39:06Z")

</div>

Hello!

I have SST file downloaded from [NASA Ocean Color](https://oceancolor.gsfc.nasa.gov/), size of  
lat: 470 & lon: 409.

If I try to plot the data as points, I get the message that the dimensions don’t match, and if I try to plot using grdimage or grdcontour I get the following message:

“Grid appears to have irregular spacing in the ‘lon’ dimension.”

These are the values of coordinates:

 ![image](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/0/01589222305a4fd44dc5d6cc06af8a733e552e33.png)

How would I go about this issue, in order to get as close as possible to this?

 ![image](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/a/aaaa5cb100d6657f5c57fced524f09fa9ebc7c77.jpeg)

Thank you! 🙂

---

<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:** [June 7, 2021, 8:24pm UTC](https://forum.generic-mapping-tools.org/t/how-to-plot-temperature/1760/2 "2021-06-07T20:24:24Z")

</div>

Your question is basically the same as [Help reading coordinates in a NETCDF GMT6.1.1](https://flint.soest.hawaii.edu/t/help-reading-coordinates-in-a-netcdf-gmt6-1-1/1456/9) … and as well my answer. But not python.

---

<div class="post-metadata">

**Author:** ![weiji14](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/weiji14/32/33_2.png) [@weiji14](https://forum.generic-mapping-tools.org/u/weiji14)\
**Post date:** [June 9, 2021, 2:11am UTC](https://forum.generic-mapping-tools.org/t/how-to-plot-temperature/1760/3 "2021-06-09T02:11:13Z")

</div>

> [@ljeonjko](#):
>
> “Grid appears to have irregular spacing in the ‘lon’ dimension.”

The error message implies that your longitude values are not equally spaced (i.e. it is an irregular grid). In your screenshot for example, 86.06917-86.027504=0.041666 is not equal to 86.027504-85.98584=0.041664. You will need to ensure that the longitude values are equally spaced before plotting in PyGMT/GMT.

One solution would be to use `xarray`’s [interp](https://xarray.pydata.org/en/stable/generated/xarray.DataArray.interp.html) function to interpolate your irregular grid onto a regular grid. You will need to specify the new `coords` (coordinate values), and the `interp` function will perform linear interpolation to convert your old grid into a new grid. The new grid can then be plotted with PyGMT/GMT.

---

<div class="post-metadata">

**Author:** ![ljeonjko](https://avatars.discourse-cdn.com/v4/letter/l/b5ac83/32.png) [@ljeonjko](https://forum.generic-mapping-tools.org/u/ljeonjko)\
**Post date:** [June 9, 2021, 6:33am UTC](https://forum.generic-mapping-tools.org/t/how-to-plot-temperature/1760/4 "2021-06-09T06:33:03Z")

</div>

> You will need to ensure that the longitude values are equally spaced before plotting in PyGMT/GMT.

Thanks! So there is no way to plot geophysical data unless its grid is equally spaced in the start? Not even contours or points? It doesn’t necessarily have to be a gridded plot.

---

<div class="post-metadata">

**Author:** ![ljeonjko](https://avatars.discourse-cdn.com/v4/letter/l/b5ac83/32.png) [@ljeonjko](https://forum.generic-mapping-tools.org/u/ljeonjko)\
**Post date:** [June 9, 2021, 6:33am UTC](https://forum.generic-mapping-tools.org/t/how-to-plot-temperature/1760/5 "2021-06-09T06:33:46Z")

</div>

Thanks for your reply! I’ll have to look further into it to make sense of the GMT languge. I’ll reply as soon as I attempt it and get results! 🙂

---

<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:** [June 9, 2021, 10:45am UTC](https://forum.generic-mapping-tools.org/t/how-to-plot-temperature/1760/6 "2021-06-09T10:45:54Z")

</div>

Wait, your example image is showing a L3 type data. Level 3 products are gridded in a regular grid (I’ve processed hundreds of them) and can be used directly by GMT. Or am I wrong and they are not L3?

---

<div class="post-metadata">

**Author:** ![ljeonjko](https://avatars.discourse-cdn.com/v4/letter/l/b5ac83/32.png) [@ljeonjko](https://forum.generic-mapping-tools.org/u/ljeonjko)\
**Post date:** [June 9, 2021, 11:51am UTC](https://forum.generic-mapping-tools.org/t/how-to-plot-temperature/1760/7 "2021-06-09T11:51:46Z")

</div>

The picture is an example, but yes, it’s L3 mapped type data that I’m using. I’m currently working on figuring out how to use the binned type, as I will need to do further analysis.

---

<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:** [June 9, 2021, 11:56am UTC](https://forum.generic-mapping-tools.org/t/how-to-plot-temperature/1760/8 "2021-06-09T11:56:03Z")

</div>

Ah, the binned type. There was once a C code in the (OC) forum or around to read the binned type, which is not regular grid but instead with cells of constant area and therefore less columns per row as lat increases.

---

<div class="post-metadata">

**Author:** ![ljeonjko](https://avatars.discourse-cdn.com/v4/letter/l/b5ac83/32.png) [@ljeonjko](https://forum.generic-mapping-tools.org/u/ljeonjko)\
**Post date:** [June 23, 2021, 1:30pm UTC](https://forum.generic-mapping-tools.org/t/how-to-plot-temperature/1760/9 "2021-06-23T13:30:06Z")

</div>

@weiji14, the **interp** works apperently nicely, I’m now able to plot the data onto coastlines. Of course, the “rawness” of the data is now a bit reduced, but it should be fine, though. I’ll test it for further validation.

Additional question, if I can find the “matching” projection of the satellite, should it theoretically be possible to directly plot the grid, without previous interpolation?

On a side note

```
fig.grdimage(
grid=ds)

```

is all that it required for grdimage to work, no need to activate `interpolation` nor `dip`. Just a tip for someone as new as me.

Thanks!
