# Several contour plots in one 3d plot

**URL:** <https://discourse.julialang.org/t/several-contour-plots-in-one-3d-plot/50986>\
**Category:** Visualization\
**Created:** [November 30, 2020, 11:50am UTC](https://discourse.julialang.org/t/several-contour-plots-in-one-3d-plot/50986 "2020-11-30T11:50:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Flausi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/flausi/32/19847_2.png) [@Flausi](https://discourse.julialang.org/u/Flausi)\
**Post date:** [November 30, 2020, 11:50am UTC](https://discourse.julialang.org/t/several-contour-plots-in-one-3d-plot/50986/1 "2020-11-30T11:50:41Z")

</div>

Hello, is there a possibility in Julia to combine several contour plots into one 3D plot like in the picture? I have tried a little bit with GLMike, but did not get it. I would be very happy if there is a solution.

![SpecifyContourLevelsAndAddColorbarExample_01](https://global.discourse-cdn.com/julialang/original/3X/2/6/260eabed54abeb55ade027e2efea27f89b2f44ae.png)

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [November 30, 2020, 4:39pm UTC](https://discourse.julialang.org/t/several-contour-plots-in-one-3d-plot/50986/2 "2020-11-30T16:39:33Z")

</div>

Maybe something like this in Makie?

```julia
using Makie

xs = LinRange(-1, 1, 100)
ys = LinRange(-1, 1, 100)
zs = [x^2+y^2 for x in xs, y in ys]

s = contour(xs, ys, zs, transformation=(:yz, -1), levels=10, limits=FRect((-2,-2,-2), (4,4,4)))
contour!(s, xs, ys, zs, transformation=(:yz, 0), levels=10)
contour!(s, xs, ys, zs, transformation=(:yz, 1), levels=10)

```

![image](https://global.discourse-cdn.com/julialang/original/3X/5/d/5d1fb589a4085110e78e56dee6dddd62daf151ef.png)

---

<div class="post-metadata">

**Author:** ![Flausi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/flausi/32/19847_2.png) [@Flausi](https://discourse.julialang.org/u/Flausi)\
**Post date:** [December 2, 2020, 7:33pm UTC](https://discourse.julialang.org/t/several-contour-plots-in-one-3d-plot/50986/3 "2020-12-02T19:33:02Z")

</div>

Thanks a lot for your help, it worked very well. There are two more things that interest me. I would like to rotate the axis labels by 90 degrees so that they run along the axis. Unfortunately I haven’t read anything in the Makie documentation yet. And is it possible to insert a legend/colorbar to make a connection between the colors and the values?

Thanks again and sorry i am still a beginner 🙂

 ![plot](https://global.discourse-cdn.com/julialang/original/3X/c/1/c1cf498c84ceb5e36c852bd5a5e7022e1a5503b2.jpeg)

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [December 3, 2020, 3:12pm UTC](https://discourse.julialang.org/t/several-contour-plots-in-one-3d-plot/50986/4 "2020-12-03T15:12:52Z")

</div>

This is a really nice plot!

Here’s a version with rotated axis labels (and rotated tick labels to match), and a colorbar using MakieLayout:

```julia
using Makie
using AbstractPlotting.MakieLayout

# Parent scence
scene, layout = layoutscene()

# Scene for main plot
lscene = layout[1, 1] = LScene(scene, camera=cam3d!, raw=false)
s = lscene.scene

# Main plot
xs = LinRange(-1, 1, 100)
ys = LinRange(-1, 1, 100)
zs = [x^2+y^2 for x in xs, y in ys]
style = (levels=10, linewidth=2)
contour!(s, xs, ys, zs, transformation=(:yz, -1); style..., limits=FRect((-2,-2,-2), (4,4,4)))
contour!(s, xs, ys, zs, transformation=(:yz, 0); style...)
contour!(s, xs, ys, zs, transformation=(:yz, 1); style...)

# Axis names
xlabel!(s, "X [mm]")
ylabel!(s, "Y [mm]")
zlabel!(s, "Z⋅10^3 [mm]")
s[Axis][:names][:rotation] = (qrotation(Vec3(0,0,1), π),
                              qrotation(Vec3(0,0,1), π/2),
                              qrotation(Vec3(0,0,1), -π/2) * qrotation(Vec3(0,1,0), -π/2))
s[Axis][:names][:align] = ((:center, :right), (:center, :right), (:center, :left))

# Axis ticks
xtickrotation!(s, 1π) # Giving an Irrational fails (probably a bug)
ytickrotation!(s, π/2)

# Colorbar
layout[1, 2] = LColorbar(scene, s[end], width=30)

scene

```

 ![contours](https://global.discourse-cdn.com/julialang/original/3X/d/7/d7463cc84f9f5f3584f14dfa30835fcabb41a72e.png)

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [December 3, 2020, 4:51pm UTC](https://discourse.julialang.org/t/several-contour-plots-in-one-3d-plot/50986/5 "2020-12-03T16:51:37Z")

</div>

Maybe you also want more ticks on the x axis, you can change this with

```julia
xticks!(s, xtickrange=0:20, xticklabels=["$x" for x in 0:20])

```

(Makie will [hopefully](https://github.com/JuliaPlots/Makie.jl/issues/773) make this easier at some point.)

Please share the final figure (and publication if any) when ready!

Also is the position on the x axis related to time? It could make a nice animation.

---

<div class="post-metadata">

**Author:** ![Flausi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/flausi/32/19847_2.png) [@Flausi](https://discourse.julialang.org/u/Flausi)\
**Post date:** [December 11, 2020, 2:35pm UTC](https://discourse.julialang.org/t/several-contour-plots-in-one-3d-plot/50986/6 "2020-12-11T14:35:14Z")

</div>

Hey, sorry for the late reply. There is a lot to do during the Christmas season 🙂

Thanks for the tip with the xticks, I almost despaired of them 😉

The publication will unfortunately take a while, but yes when it’s ready I can share it here.

I have also thought about an animation, but in the spatial presentation you can see the development of the shape at first look.

Thank you and stay healthy
