<p>There are two stages to what you want here.</p>

<h2>1. Converting point data to gridded data</h2>

<p>First off, since you want to plot regular cells rather than the actual data that you have, you need to covert your point data to cells in some way. The best way to do this may depend on the data itself, but one way would be to interpolate, perhaps using something along the lines of,</p>

<pre><code>SI = scatteredInterpolant(Lon, Lat, Rain, 'natural', 'linear')
% read up on and understand the last two parameters before choosing what to use

%form the grid, with points 1 degree apart. 
gx = min(Lon):1:max(Lon);
gy = min(Lat):1:max(Lat);
[ X, Y ] = meshgrid(gx, gy);

%produce an actual grid of rain data
gridded = SI(X,Y);
</code></pre>

<p>Alternatively, if your point data has a much higher resolution than the 1 degree grid, <em>and if it is regularly spaced</em>, you could simply take the mean of the points that lie in each cell.</p>

<h2>2. Plotting that grid</h2>

<p>A naive method, which might be helpful as a quick check that what comes before has worked, would be,</p>

<pre><code>figure;
imagesc(flipud(gridded));
colorbar;
</code></pre>

<p>However, that will treat lon and lat as x and y coordinates on a rectilinear grid. To plot with a projection (N.B., WGS84 is not a projection. You'll need to figure out exactly what you're after with more clarity), you ideally want the <a href="https://uk.mathworks.com/products/mapping/" rel="nofollow">Mapping Toolbox</a>. I'm not an expert on that, but it should make projected plots relatively straightfoward.</p>

<p>If you don't have access to the Mapping Toolbox, then you could spend a lot of time faffing with coordinate transforms to do what you want... but my advice would be to spend the time learning the basics of a GIS package instead (<a href="http://qgis.org" rel="nofollow">QGIS</a> is free) and use that to do the job.</p>

CC BY-SA 3.0
2017-11-16T02:43:34.410Z
I doubt `scatteredInterpolant` is a good way to interpolate the lat-lon data. It's not the same as xy data
wsdzbm
CC BY-SA 3.0
2017-11-16T04:46:53.953Z
@Lee that's a fair point. Only use scatteredInterpolant if it's reasonable to treat lon/lat as cartesian coordinates for what you're doing, ie it's at fairly large scale and not near the poles.
Semidiurnal Simon
CC BY-SA 3.0
2015-08-20T09:08:41.440Z
2015-08-21T10:09:49.393Z
2015-08-21T10:09:49.393Z
Semidiurnal Simon
<p>What kind of plot do you want? </p>

<blockquote>
  <p>Lat = [25.5 26.5 33.5 34.5 35.5 36.5 41.5 42.5]; </p>
  
  <p>Lon = [89.5 91.5 78.5 79.5 83.5 84.5 75.5 76.5]; </p>
  
  <p>Rain = [110 120 122 135 114 116 145 120 110 110];</p>
  
  <p>figure();</p>
  
  <p>plot3(Lat,Lon,Rain,'o')</p>
</blockquote>

<p>will give you a scatter plot with Lat being the x, Lon being the y, and rain being the z.</p>

<p>Also note that because your vectors are different legnths, you cannot plot them. You must have vectors of the same lenght to plot (each point must correspond to another point on the axis).</p>

<p>Other types of plots will require you to interpolate between the data points.  </p>

<p>If you want to plot it like in the comment below: <strong>pcolor</strong> is your best choice.</p>

<p>Say your Lat/Lon vectors have n points. Then to make an nxn grid, you can use the command</p>

<blockquote>
  <p>[X,Y] = meshgrid(Lat,Lon);</p>
</blockquote>

<p>This will give you the grid you want, as long as your Lat/Lon Vectors are spaced how you want. To get the 'color" of the pcolor, you will need to have a nxn matrix of rain values: you will need to know what those are at each point. If you do not know those, then then you cannot plot it in map view unless you do some form of modeling or interpolation. </p>

<p>If you have an irregular shape, I would not use matlab. I would use Visit or Paraview, and there are many guides online on how to use this.</p>

<p>If you must use matlab, I would create "fake points" to make the grid a regular shape, and give them false rain values (such as NaN). I would then edit the plot in a postprocessor (photoshop) so that Only the irregular shape appears. </p>

<p>The spacing of the grid does not matter as its specified via your vectors. </p>

CC BY-SA 3.0
2015-08-20T05:54:32.127Z
Thanks Neo. I want to plot it like a map, please see the link (https://i.sstatic.net/ygDyf.jpg) . Each point will have a cell size of 1 degree, and there must be WGS 84 projection.
dsbisht
CC BY-SA 3.0
2015-08-20T06:06:15.907Z
Thanks again, I have edited the question. Lat-Lon which I have represent an irregular area, which will create problem with meshgrid.
dsbisht
CC BY-SA 3.0
2015-08-20T06:17:32.093Z
My answer has been edited. It seems you are using the wrong tool.
Neo
CC BY-SA 3.0
2015-08-20T06:23:00.510Z
Many Thanks !! I would be doing some trend analysis and other test in MATLAB and will be plotting result. So I have to go with MATLAB. Seems it can be done with "geoloc2grid" in Matlab.
dsbisht
CC BY-SA 3.0
2015-08-20T07:01:03.070Z
I do almost all my analysis in matlab, but almost never plot in matlab for publication, for what its worth. You can export data from matlab (by writing a text file or w/e) which might make it easier to visualize. GMT is especially good at making the plots you seek.
Neo
CC BY-SA 3.0
2015-08-20T09:12:31.710Z
Neo: check your X,Y vs Lat,Lon - you have them backwards (well, unless you want north to be on the right) :-)
Semidiurnal Simon
CC BY-SA 3.0
2015-08-20T05:31:33.373Z
2015-08-20T06:16:48.290Z
2015-08-20T06:16:48.290Z
Neo
<p>I have average annual rainfall values at few grids, as shown in below example;</p>

<p>Lat: 25.5 26.5 33.5 34.5 35.5 36.5 41.5 42.5</p>

<p>Lon: 89.5 91.5 78.5 79.5 83.5 84.5 75.5 76.5</p>

<p>Rain: 110 120 122 135 114 116 145 120 110 110</p>

<p>I want to plot it like a map, like this example</p>

<p><a href="https://i.sstatic.net/ygDyf.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ygDyf.jpg" alt="Example plots"></a></p>

<p>Each point will have a cell size of 1 degree, and there must be WGS 84 projection. How to plot them in MATLAB ?</p>

<p>I have around 4000 lat-lon values and these are not in sequence. Moreover the available Lat-Lon represent the irregular shape. </p>

CC BY-SA 3.0
2015-08-20T09:09:43.950Z
WGS84 is not a projection. It can refer to a geoid, or a datum. However, the answer doesn't really depend on what specific projection you want; the important thing is that you need to project the output, you can figure out the exact projection later :)
Semidiurnal Simon
CC BY-SA 3.0
2015-08-20T09:45:16.043Z
Do you have access to the Mapping Toolbox?  If you're not sure, type `ver` in interactive Matlab.
gerrit
CC BY-SA 3.0
2015-08-20T11:46:10.680Z
Using Python with [basemap](http://matplotlib.org/basemap/users/examples.html) makes it easy.  FYI...
user2821
CC BY-SA 3.0
2015-08-20T20:43:56.347Z
Alternative to the [Mapping Toolbox](http://www.mathworks.com/products/mapping/) you can try the [M_Map mapping package](http://www.eos.ubc.ca/~rich/map.html).
BHF
<meteorology><hydrology><matlab><visualization>
How to plot lat-lon-rainfall in MATLAB?
dsbisht
# How to plot lat-lon-rainfall in MATLAB?

(Asked by: username_0 on 2015-08-20)

I have average annual rainfall values at few grids, as shown in below example;

Lat: 25.5 26.5 33.5 34.5 35.5 36.5 41.5 42.5

Lon: 89.5 91.5 78.5 79.5 83.5 84.5 75.5 76.5

Rain: 110 120 122 135 114 116 145 120 110 110

I want to plot it like a map, like this example

[![Example plots](https://i.sstatic.net/ygDyf.jpg)](https://i.sstatic.net/ygDyf.jpg)

Each point will have a cell size of 1 degree, and there must be WGS 84 projection. How to plot them in MATLAB ?

I have around 4000 lat-lon values and these are not in sequence. Moreover the available Lat-Lon represent the irregular shape.

**Tags:** meteorology, hydrology, matlab, visualization

> **Comments:**
> **username_1**: WGS84 is not a projection. It can refer to a geoid, or a datum. However, the answer doesn't really depend on what specific projection you want; the important thing is that you need to project the output, you can figure out the exact projection later :)  
> **username_2**: Do you have access to the Mapping Toolbox?  If you're not sure, type `ver` in interactive Matlab.  
> **username_3**: Using Python with [basemap](http://matplotlib.org/basemap/users/examples.html) makes it easy.  FYI...  
> **username_4**: Alternative to the [Mapping Toolbox](http://www.mathworks.com/products/mapping/) you can try the [M_Map mapping package](http://www.eos.ubc.ca/~rich/map.html).  

---

## 2 answers

### Answer by username_1 on 2015-08-20. Score: 4

There are two stages to what you want here.

## 1. Converting point data to gridded data

First off, since you want to plot regular cells rather than the actual data that you have, you need to covert your point data to cells in some way. The best way to do this may depend on the data itself, but one way would be to interpolate, perhaps using something along the lines of,

```
SI = scatteredInterpolant(Lon, Lat, Rain, 'natural', 'linear')
% read up on and understand the last two parameters before choosing what to use

%form the grid, with points 1 degree apart. 
gx = min(Lon):1:max(Lon);
gy = min(Lat):1:max(Lat);
[ X, Y ] = meshgrid(gx, gy);

%produce an actual grid of rain data
gridded = SI(X,Y);

```

Alternatively, if your point data has a much higher resolution than the 1 degree grid, *and if it is regularly spaced*, you could simply take the mean of the points that lie in each cell.

## 2. Plotting that grid

A naive method, which might be helpful as a quick check that what comes before has worked, would be,

```
figure;
imagesc(flipud(gridded));
colorbar;

```

However, that will treat lon and lat as x and y coordinates on a rectilinear grid. To plot with a projection (N.B., WGS84 is not a projection. You'll need to figure out exactly what you're after with more clarity), you ideally want the [Mapping Toolbox](https://uk.mathworks.com/products/mapping/). I'm not an expert on that, but it should make projected plots relatively straightfoward.

If you don't have access to the Mapping Toolbox, then you could spend a lot of time faffing with coordinate transforms to do what you want... but my advice would be to spend the time learning the basics of a GIS package instead ([QGIS](http://qgis.org) is free) and use that to do the job.

> **Comments:**
> **username_5**: I doubt `scatteredInterpolant` is a good way to interpolate the lat-lon data. It's not the same as xy data  
> **username_1**: @Lee that's a fair point. Only use scatteredInterpolant if it's reasonable to treat lon/lat as cartesian coordinates for what you're doing, ie it's at fairly large scale and not near the poles.  

---

### Answer by username_6 on 2015-08-20. Score: 4

What kind of plot do you want?

> Lat = [25.5 26.5 33.5 34.5 35.5 36.5 41.5 42.5];
>
> Lon = [89.5 91.5 78.5 79.5 83.5 84.5 75.5 76.5];
>
> Rain = [110 120 122 135 114 116 145 120 110 110];
>
> figure();
>
> plot3(Lat,Lon,Rain,'o')

will give you a scatter plot with Lat being the x, Lon being the y, and rain being the z.

Also note that because your vectors are different legnths, you cannot plot them. You must have vectors of the same lenght to plot (each point must correspond to another point on the axis).

Other types of plots will require you to interpolate between the data points.

If you want to plot it like in the comment below: **pcolor** is your best choice.

Say your Lat/Lon vectors have n points. Then to make an nxn grid, you can use the command

> [X,Y] = meshgrid(Lat,Lon);

This will give you the grid you want, as long as your Lat/Lon Vectors are spaced how you want. To get the 'color" of the pcolor, you will need to have a nxn matrix of rain values: you will need to know what those are at each point. If you do not know those, then then you cannot plot it in map view unless you do some form of modeling or interpolation.

If you have an irregular shape, I would not use matlab. I would use Visit or Paraview, and there are many guides online on how to use this.

If you must use matlab, I would create "fake points" to make the grid a regular shape, and give them false rain values (such as NaN). I would then edit the plot in a postprocessor (photoshop) so that Only the irregular shape appears.

The spacing of the grid does not matter as its specified via your vectors.

> **Comments:**
> **username_0**: Thanks Neo. I want to plot it like a map, please see the link (https://i.sstatic.net/ygDyf.jpg) . Each point will have a cell size of 1 degree, and there must be WGS 84 projection.  
> **username_0**: Thanks again, I have edited the question. Lat-Lon which I have represent an irregular area, which will create problem with meshgrid.  
> **username_6**: My answer has been edited. It seems you are using the wrong tool.  
> **username_0**: Many Thanks !! I would be doing some trend analysis and other test in MATLAB and will be plotting result. So I have to go with MATLAB. Seems it can be done with "geoloc2grid" in Matlab.  
> **username_6**: I do almost all my analysis in matlab, but almost never plot in matlab for publication, for what its worth. You can export data from matlab (by writing a text file or w/e) which might make it easier to visualize. GMT is especially good at making the plots you seek.  
> **username_1**: Neo: check your X,Y vs Lat,Lon - you have them backwards (well, unless you want north to be on the right) :-)  

---

