# Rotatable 3D plot in jupyter

**URL:** <https://discourse.julialang.org/t/rotatable-3d-plot-in-jupyter/70535>\
**Category:** Visualization\
**Tags:** jupyter, plotting, makie\
**Created:** [October 28, 2021, 6:56am UTC](https://discourse.julialang.org/t/rotatable-3d-plot-in-jupyter/70535 "2021-10-28T06:56:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![HenrikM](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrikm/32/17975_2.png) [@HenrikM](https://discourse.julialang.org/u/HenrikM)\
**Post date:** [October 28, 2021, 6:56am UTC](https://discourse.julialang.org/t/rotatable-3d-plot-in-jupyter/70535/1 "2021-10-28T06:56:04Z")

</div>

How to make a rotatable 3D plot in Jupyter?

For example, from the REPL, this works by opening a new tab in my browser:

```julia
using WGLMakie
let x = LinRange(-1,1,31), f(x,y) = x^2 - y^2
   surface(x,x,f.(x,x'))
end

```

In the tab, there is a beautiful rotatable 3d picture. However, evaluating the same in a Jupyter cell only fires up the CPU for a couple of minutes and produces nothing. I tried the example at [How to use JSServe + WGLMakie](http://juliaplots.org/WGLMakie.jl/dev/#How-to-use-JSServe-WGLMakie). In a Jupyter cell:

```julia
using JSServe
Page(exportable=true, offline=true)
using WGLMakie
let x = LinRange(-1,1,31), f(x,y) = x^2 - y^2
   surface(x,x,f.(x,x'))
end

```

Again, the CPU works hard for a while and nothing is produced.

This is essentially the same question as [Makie 3d plot cannot rotate in jupyter notebook?](https://discourse.julialang.org/t/makie-3d-plot-cannot-rotate-in-jupyter-notebook/68191), but I did not want to highjack that thread.

It does not have to be Makie, any other plotting library is fine. For everyday work, I use [Plots.jl](https://github.com/JuliaPlots/Plots.jl), but rotatable 3D plots is the one feature I am really missing.

---

<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 28, 2021, 7:39am UTC](https://discourse.julialang.org/t/rotatable-3d-plot-in-jupyter/70535/2 "2021-10-28T07:39:05Z")

</div>

PLotlyJS generates interactive plots:

```julia
using PlotlyJS

f(x,y) = 60 * cos(2 * atan(y/x) + 0.544331*sqrt(x^2+y^2)) / (20+sqrt(x^2+y^2))
x = LinRange(-45, 45, 200)
z = [f(u, v) for u in x, v in x]
waves = surface(
            z=z, 
            x=x,  
            y=x,  
            colorscale=colors.viridis,
            showscale=false)
Plot(waves, Layout(width=600, height=600, 
                   scene= attr(aspectmode="data",
                               camera_eye=attr(x=2.55, y=2.55, z=1.4)))

```

---

<div class="post-metadata">

**Author:** ![HenrikM](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrikm/32/17975_2.png) [@HenrikM](https://discourse.julialang.org/u/HenrikM)\
**Post date:** [October 28, 2021, 10:16am UTC](https://discourse.julialang.org/t/rotatable-3d-plot-in-jupyter/70535/3 "2021-10-28T10:16:24Z")

</div>

Great, thank you! Last time I tried this I had problems with WebIO, can’t remember exactly what.

Now also this works:

```julia
using Plots
plotlyjs()

let x = LinRange(-1,1,31), f(x,y) = x^2 - y^2
   surface(x,x,f)
end

```
