# 3D Heatmap

**URL:** <https://discourse.julialang.org/t/3d-heatmap/70658>\
**Category:** Visualization\
**Tags:** pyplot, plots, plotlyjs\
**Created:** [October 30, 2021, 11:25am UTC](https://discourse.julialang.org/t/3d-heatmap/70658 "2021-10-30T11:25:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![skolari93](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skolari93/32/30359_2.png) [@skolari93](https://discourse.julialang.org/u/skolari93)\
**Post date:** [October 30, 2021, 11:25am UTC](https://discourse.julialang.org/t/3d-heatmap/70658/1 "2021-10-30T11:25:30Z")

</div>

Hello!  
Is there a way creatinge a 3D heatplot using Plots.jl?

I try to visualize a 4D plot by plotting a 3D sphere and coloring the surface according to a function f.  
This is the closest I was able to do:

```julia
plot(x,y,z, st=:surface)

```

but now I would like to set the colors on the surface by a function f(x,y,z) and not according to the height z.

Thank you for your help

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [October 30, 2021, 12:55pm UTC](https://discourse.julialang.org/t/3d-heatmap/70658/2 "2021-10-30T12:55:45Z")

</div>

You can use Plots.jl `pyplot()` or `plotlyjs()` backends to produce something like this:  
 ![Plots_plotlyjs_3d_surface_heatmap](https://global.discourse-cdn.com/julialang/original/3X/9/5/95f67694521fe563b13bb5a838f6977baed25ff1.png)

Code example:

```julia
using Plots; plotlyjs() #or: pyplot()
n = 300
θ = LinRange(0,π,n)
ϕ = LinRange(0,2π,n)
xx = @. sin(θ)*cos(ϕ')
yy = @. sin(θ)*sin(ϕ')
zz = @. cos(θ)*ones(n)'
surface(xx, yy, zz, fill_z = 5*sin.(10xx .* yy), size=(600,600))

```

The user function needs to be mapped onto the meshgrid and then `fill_z` takes over to assign colors from the colormap.

---

<div class="post-metadata">

**Author:** ![skolari93](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skolari93/32/30359_2.png) [@skolari93](https://discourse.julialang.org/u/skolari93)\
**Post date:** [October 30, 2021, 5:06pm UTC](https://discourse.julialang.org/t/3d-heatmap/70658/3 "2021-10-30T17:06:46Z")

</div>

Thank you a lot!

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [October 30, 2021, 8:37pm UTC](https://discourse.julialang.org/t/3d-heatmap/70658/4 "2021-10-30T20:37:43Z")

</div>

Let us know if you get a nice plot on the sphere that you can share.

It’s always fun to see what one can get by poking mathematical functions around:

_Ex.1.1: Golden stripes-1_

 ![Plots_plotlyjs_3d_surface_heatmap_gold_stripes](https://global.discourse-cdn.com/julialang/original/3X/9/b/9b231cadde1a9f186a7f1132498728514660d67b.png)  
_Ex.1.2: Golden stripes-2_  
 ![Plots_plotlyjs_3d_surface_heatmap_gold_stripes2](https://global.discourse-cdn.com/julialang/original/3X/2/b/2b3e7d89bbdd52a19a99e7878bce581d4fa468cf.png)  
_Ex.1.3: Golden stripes-3_  
 ![Plots_plotlyjs_3d_surface_heatmap_gold_stripes3](https://global.discourse-cdn.com/julialang/original/3X/a/b/ab7de488b8e94b007efe6f256d115d955cdabf04.png)

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [October 30, 2021, 8:51pm UTC](https://discourse.julialang.org/t/3d-heatmap/70658/5 "2021-10-30T20:51:32Z")

</div>

what function is this?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [October 30, 2021, 9:08pm UTC](https://discourse.julialang.org/t/3d-heatmap/70658/6 "2021-10-30T21:08:53Z")

</div>

How about a little game to spice things up, inviting interested people to share examples without revealing the underlying mathematical function, say until Christmas? 🎄

---

<div class="post-metadata">

**Author:** ![skolari93](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skolari93/32/30359_2.png) [@skolari93](https://discourse.julialang.org/u/skolari93)\
**Post date:** [October 30, 2021, 9:34pm UTC](https://discourse.julialang.org/t/3d-heatmap/70658/7 "2021-10-30T21:34:40Z")

</div>

looks great!

I was doing something very classic:

 ![grafik](https://global.discourse-cdn.com/julialang/original/3X/5/9/59221f96120978d03c18dcf4506b939cd9e6401b.jpeg)

I will definitly play around more 🙂

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [October 31, 2021, 12:44pm UTC](https://discourse.julialang.org/t/3d-heatmap/70658/8 "2021-10-31T12:44:59Z")

</div>

![sphere-Julia](https://global.discourse-cdn.com/julialang/original/3X/f/c/fcf00b228d79a14e5be71b46bc8dc8ff24c3ad3f.png)

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [November 1, 2021, 10:48am UTC](https://discourse.julialang.org/t/3d-heatmap/70658/9 "2021-11-01T10:48:05Z")

</div>

Bezier surface colormapped according to the green component values of a cat image.  
 ![cat-on-bezierSNV](https://global.discourse-cdn.com/julialang/original/3X/7/d/7dde5c508f3871627d7730132c8f026180fdf129.png)  
A different camera eye position:  
 ![cat-on-bezierS](https://global.discourse-cdn.com/julialang/original/3X/1/0/104eaf5e320c3620123147693a9fa1546b1e34ba.png)
