<p>You basically need to plot the scatter map with varying colors for each point</p>

<pre><code>scatter(x, y, [], c);
</code></pre>

<p>The main difficulty is to calculate<code>c</code> so that it’s proportional to the density. </p>

<p>To do so you can divide the map into a grid of a certain resolution, say <code>[res_x, res_y]</code>. Then count for each grid cell how many points are there. This count is an approximation of the density at that grid cell. Finally you can assign to all points within this grid cell the <code>c</code> value equal this count. </p>

<p>Probably you also need to normalize <code>c</code> to <code>[0, 1]</code></p>

CC BY-SA 3.0
2017-11-15T04:17:39.013Z
Thank you for your help, I can understand your answer, but I don’t know which function should I choice to calculate the density?
user239932
CC BY-SA 3.0
2017-11-16T14:31:44.680Z
That's already in the answer: use the count.
Pikalek
CC BY-SA 3.0
2017-11-14T16:58:08.963Z
2017-11-14T16:58:08.963Z
mushin
<p>I have two columns of data, x(angle) and y(distance), they are my experiment results(figure 1). How can I use these results to make a ‘hotmap diagram’ by matlab? The z axis is the density value of xy dots in the 2D coordinate department, like below figure2. Thank you!
<a href="https://i.sstatic.net/CVbH8.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/CVbH8.jpg" alt="enter image description here"></a>
<a href="https://i.sstatic.net/swpBg.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/swpBg.jpg" alt="enter image description here"></a></p>

<image-processing><mathematics>
Matlab scatter hotmap
user239932
# Matlab scatter hotmap

(Asked by: username_0 on 2017-11-13)

I have two columns of data, x(angle) and y(distance), they are my experiment results(figure 1). How can I use these results to make a ‘hotmap diagram’ by matlab? The z axis is the density value of xy dots in the 2D coordinate department, like below figure2. Thank you!
[![enter image description here](https://i.sstatic.net/CVbH8.jpg)](https://i.sstatic.net/CVbH8.jpg)
[![enter image description here](https://i.sstatic.net/swpBg.jpg)](https://i.sstatic.net/swpBg.jpg)

**Tags:** image-processing, mathematics


---

## 1 answers

### Answer by username_1 on 2017-11-14. Score: 1 | Accepted answer

You basically need to plot the scatter map with varying colors for each point

```
scatter(x, y, [], c);

```

The main difficulty is to calculate`c` so that it’s proportional to the density.

To do so you can divide the map into a grid of a certain resolution, say `[res_x, res_y]`. Then count for each grid cell how many points are there. This count is an approximation of the density at that grid cell. Finally you can assign to all points within this grid cell the `c` value equal this count.

Probably you also need to normalize `c` to `[0, 1]`

> **Comments:**
> **username_0**: Thank you for your help, I can understand your answer, but I don’t know which function should I choice to calculate the density?  
> **username_2**: That's already in the answer: use the count.  

---

