# Light position for 3D surface plots with bands

**URL:** <https://discourse.julialang.org/t/light-position-for-3d-surface-plots-with-bands/95823>\
**Category:** Visualization\
**Tags:** plotting, graphics, makie, 3d, glmakie\
**Created:** [March 9, 2023, 9:05pm UTC](https://discourse.julialang.org/t/light-position-for-3d-surface-plots-with-bands/95823 "2023-03-09T21:05:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yhchang96](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yhchang96/32/36499_2.png) [@yhchang96](https://discourse.julialang.org/u/yhchang96)\
**Post date:** [March 9, 2023, 9:05pm UTC](https://discourse.julialang.org/t/light-position-for-3d-surface-plots-with-bands/95823/1 "2023-03-09T21:05:31Z")

</div>

I tried following the example in this [tutorial](https://beautiful.makie.org/dev/examples/generated/2d/surfaces/surface_filled_sides/#sides-colour-gradient-bottom-to-top) to create a 3D surface plot with a ‘side band’:

```julia
using GLMakie; GLMakie.activate!() # v.0.8.2

cmap = Reverse(:Spectral_4)
lightpos1 = Vec3f(4, -5, 5)

set_theme!()
update_theme!(
    lightposition = lightpos1,
    Axis3 = (protrusions = 0, elevation = pi/4, azimuth = -pi/3),
    Surface = (specular = Vec3f(0.2), shading = true, diffuse = Vec3f(0.8)),
    Band = (specular = Vec3f(0.2), shading = true, diffuse = Vec3f(0.8)),
)

# generate data for sample plot:
x = range(-3, 3, length=100)
y = range(-2, 2, length=100)
z = [sin(x + y^2) for x in x, y in y]
xpt = [x for x in x, y in y]
ypt = [y for x in x, y in y];

function boundary_values(a)
    return [a[1,:]..., a[2:end,end]..., a[end,end-1:-1:1]...,a[end-1:-1:1,1]...]
end

bxpt = boundary_values(xpt)
bypt = boundary_values(ypt)
bzpt = boundary_values(z)

upper = Point3f.(bxpt, bypt, bzpt)
lower = Point3f.(bxpt, bypt, bzpt*0.0 .+ minimum(bzpt))
lower_colors = bzpt*0.0 .+ minimum(bzpt);

###########################################################################################

fig = Figure()
ax = Axis3(fig[1,1]; aspect =(1,1,0.5))

surface!(ax, xpt, ypt, z; colormap=cmap, shading=true)
band!(ax, lower, upper; color = [lower_colors..., bzpt...], colormap=cmap)

fig

```

The results look like this:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/1/d1e6db136ad635a4b627b44c295d7e51bef3231c.jpeg)

Since I set the `lightposition` to `Vec3f(4, -5, 5)`, I expect a light source located at `(x,y,z)=(4,-5,5)` (please correct me if I misinterpret `lightposition`). From the figure, it does look like the light source comes from somewhere near the specified coordinates based on the color shading, but the color shading at the side bands doesn’t look right. When I rotate the 3D plot in the pop-up window to inspect the color shading, it looks like the apparent light position for the `band` is rotated by 180 degree in the x-y plane compared to that for the `surf`:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/9/d950a2cfb0ed79d3054c6789b8ea0bf109cafe2c.jpeg)

Is this a bug or are there some tricks in setting the light position?

---

<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 10, 2023, 4:57am UTC](https://discourse.julialang.org/t/light-position-for-3d-surface-plots-with-bands/95823/2 "2023-03-10T04:57:10Z")

</div>

Probably the normals are flipped the other way. Maybe you can specify the side bands with x and y reversed?
