# Code Circular Heat map with P5

**URL:** https://discourse.processing.org/t/code-circular-heat-map-with-p5/10561
**Category:** Project Guidance
**Created:** [April 23, 2019, 10:37am UTC](https://discourse.processing.org/t/code-circular-heat-map-with-p5/10561 "2019-04-23T10:37:14Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![bram94](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@bram94](https://discourse.processing.org/u/bram94)
#### Post date: [April 23, 2019, 10:37am UTC](https://discourse.processing.org/t/code-circular-heat-map-with-p5/10561/1 "2019-04-23T10:37:14Z")

</div>

Hi all,

I am very new to P5 and want to code a circular heatmap inP5 based on data I have

Something similar like shown in the figure.

I already manage to do it in R, but really need to do it in p5 and already unsucessfully searched the internet for hours and days to find sample code of how to code a circular heatmap in P5.js.

Someone any idea ?

Thanks in advance for your help!

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/8ae47027b89dbd52ff44cc84db798e18442597e5.jpeg)

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [April 23, 2019, 12:38pm UTC](https://discourse.processing.org/t/code-circular-heat-map-with-p5/10561/2 "2019-04-23T12:38:18Z")

</div>

a first start could be just a circular plot  
here a version with only 2 data series & axis ( zoom )  
[https://editor.p5js.org/kll/sketches/2AlyhU2Hg](https://editor.p5js.org/kll/sketches/2AlyhU2Hg)  
 ![SNAG-0083](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/0f9a29aaa5e50010694bc2cde6087ce68ba6bcd4.jpeg)

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [April 26, 2019, 10:54am UTC](https://discourse.processing.org/t/code-circular-heat-map-with-p5/10561/3 "2019-04-26T10:54:50Z")

</div>

Is there a specific reason you want to do this in p5.js and not d3? Just asking, because d3 has a lot of fully developed modules just for things like data driven circular heat maps.

The easiest way to draw a collection of radial segments like this is:

1. import tabular data – a 2D array or p5.js Table ([https://p5js.org/reference/#/p5.Table](https://p5js.org/reference/#/p5.Table))
2. loop over the table like a checkerboard – starting from the **outer row** and moving **inward** , so that each row of the data is a ring on your chart, with one tile per column. Outer first – this maters for rendering. If your data is organized inner-first then loop over it backwards.
3. Draw each tile using arc: [https://p5js.org/reference/#/p5/arc](https://p5js.org/reference/#/p5/arc). Your arc width is TWO\_PI / columnCount. These tiles are actually pie slices, but the inner rings will crop them to tiles.
4. Add a hole at the center with circle / ellipse.

[https://editor.p5js.org/jeremydouglass@gmail.com/sketches/W6kHic5NU](https://editor.p5js.org/jeremydouglass@gmail.com/sketches/W6kHic5NU)

---

<div class="post-metadata">

### Author: ![bram94](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@bram94](https://discourse.processing.org/u/bram94)
#### Post date: [June 8, 2019, 6:55pm UTC](https://discourse.processing.org/t/code-circular-heat-map-with-p5/10561/4 "2019-06-08T18:55:56Z")

</div>

I have now a simple circular plot.

Any idea whether it is possible (and how it is possible) to connect the dots with a line and transparant layer as sketched in the figure below in P5 ?

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/3cbb9bd0c31c4da4e4fa9e5dc57750197519cae3.jpeg)

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [June 8, 2019, 8:36pm UTC](https://discourse.processing.org/t/code-circular-heat-map-with-p5/10561/5 "2019-06-08T20:36:27Z")

</div>

It is possible to connect dots to form a shape, for example using beginShape / endShape and vertex:

[https://p5js.org/reference/#/p5/beginShape](https://p5js.org/reference/#/p5/beginShape)

The question is how your points are currently encoded, as you have not shared your sketch.

---

<div class="post-metadata">

### Author: ![bram94](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@bram94](https://discourse.processing.org/u/bram94)
#### Post date: [June 8, 2019, 8:53pm UTC](https://discourse.processing.org/t/code-circular-heat-map-with-p5/10561/6 "2019-06-08T20:53:37Z")

</div>

The points are coded as in the follow example: [https://editor.p5js.org/kll/sketches/2AlyhU2Hg](https://editor.p5js.org/kll/sketches/2AlyhU2Hg)

What I want is something as displayed on the sketch in my last post (see above). In that sketch, the transparant layer is sketched with PowerPoint and looks not smooth , so therefero I hope this would be possible in P5 to add a kind of transparant layer connecting the blue dots and a second transparant layer in green connecting the green dots on the sketch provided in my last response.

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [June 8, 2019, 9:47pm UTC](https://discourse.processing.org/t/code-circular-heat-map-with-p5/10561/7 "2019-06-08T21:47:52Z")

</div>

Well, because you are using rotate and essentially drawing with polar coordinates, this is a bit harder than it needs to be, but not too bad.

1. refactor `draw_circplot()` so that you call it twice – once for each data series
2. use beginShape / vertex / endShape to draw your shaded outlines
3. in order to do this, you must convert your polar coordinates into cartesian. That’s pretty easy; the formulas are x = r \* cos(theta) … y = r \* sin(theta).

[https://editor.p5js.org/jeremydouglass/sketches/cOOYg9SIi](https://editor.p5js.org/jeremydouglass/sketches/cOOYg9SIi)

![08%20PM](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/b74d18ee53730301ad0122d8eb45e210d58f71cc.png)
