# 3D terrain graph with colour (as 4th dimension of dataset)

**URL:** https://discourse.julialang.org/t/3d-terrain-graph-with-colour-as-4th-dimension-of-dataset/112178
**Category:** Geo
**Tags:** question, plotting
**Created:** [March 27, 2024, 12:50pm UTC](https://discourse.julialang.org/t/3d-terrain-graph-with-colour-as-4th-dimension-of-dataset/112178 "2024-03-27T12:50:03Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Qmot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qmot/32/208041_2.png) [@Qmot](https://discourse.julialang.org/u/Qmot)
#### Post date: [March 27, 2024, 12:50pm UTC](https://discourse.julialang.org/t/3d-terrain-graph-with-colour-as-4th-dimension-of-dataset/112178/1 "2024-03-27T12:50:03Z")

</div>

Hello,

Relatively new to Julia and enjoying it a lot! However, I would like to display data that has 4 dimensions, x, y, z (terrain) with a color that is independent of z. For context I’m trying to display geophysics on top of a terrain map. I’ve gone through Makie.jl, PlotlyJS.jl and Plots.jl and can’t quite find anything that suitable.

Do I need to transform my terrain data into an stl file and than overlay it with color using Makie.jl perhaps?

Any ideas to modules to consider would be great!  
Thanks

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [March 27, 2024, 1:03pm UTC](https://discourse.julialang.org/t/3d-terrain-graph-with-colour-as-4th-dimension-of-dataset/112178/2 "2024-03-27T13:03:27Z")

</div>

See the GMT.jl module [grdview](https://www.generic-mapping-tools.org/GMTjl_doc/documentation/modules/grdview/index.html#grdview). You want specifically the option `drape`.

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [March 27, 2024, 1:22pm UTC](https://discourse.julialang.org/t/3d-terrain-graph-with-colour-as-4th-dimension-of-dataset/112178/3 "2024-03-27T13:22:14Z")

</div>

Do you mean something like this?

```julia
using GLMakie
using DelimitedFiles

volcano = readdlm(Makie.assetpath("volcano.csv"), ',', Float64)
color = rand(size(volcano)...)

surface(volcano;
    color,
    axis=(type=Axis3, azimuth = pi/4))

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/8/68e18c32818783b1430b1e3deb715748cab298f6.jpeg)

---

<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: [March 27, 2024, 6:59pm UTC](https://discourse.julialang.org/t/3d-terrain-graph-with-colour-as-4th-dimension-of-dataset/112178/4 "2024-03-27T18:59:24Z")

</div>

This is a PlotlyJS example. x,y are artificially added, because my data file contains only information on z.  
Your color (the 4th dimension) should be assigned to `surfacecolor`. Here it is set `surfacecolor= z`.

```julia
using DelimitedFiles, PlotlyJS

z = readdlm("st-helens-before.txt", ' ')
r, c = size(z)
x = 1:c
y = 1:r

fig=Plot([surface(x=x, y=y, z=z, surfacecolor=z, 
        colorscale=colors.gist_earth, colorbar_thickness=25, colorbar_len=0.75
        ), surface(x=x, y=y, z=-1000*ones(size(z)), surfacecolor=z,
                        colorscale=colors.gist_earth,
                        showscale=false)],
Layout(width=500, height=500, font_size=10, scene_camera_eye=attr(x=1.6, y=1.6, z=1)))

```

![St-Helens-before](https://global.discourse-cdn.com/julialang/original/3X/2/9/29a292c0cba68734937f5362d8bd191b3a2ed1e5.png)

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [March 27, 2024, 7:54pm UTC](https://discourse.julialang.org/t/3d-terrain-graph-with-colour-as-4th-dimension-of-dataset/112178/5 "2024-03-27T19:54:43Z")

</div>

I’ll add this as an example of `grdview` plus draping an external image.

```julia
using GMT

# Get the Gulf of Guinea grid
G = grdcut("@earth_relief_01m", region=(0,10,0,10));

# Drape a photo of a cork tree trunk over it
grdview(G, shade="+nt0.5", proj=:merc, view=(145,35), drape="@wood_texture.jpg",
             zsize=5, surftype=:img, name="texture.jpg", show=true)

```

 ![texture](https://global.discourse-cdn.com/julialang/original/3X/4/c/4c3ae783c78ed3b3080b92d5d5ba5f548fb58c23.jpeg)
