Rotatable 3D plot in jupyter

How to make a rotatable 3D plot in Jupyter?

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

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. In a Jupyter cell:

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?, 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, but rotatable 3D plots is the one feature I am really missing.

PLotlyJS generates interactive plots:

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)))
1 Like

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

Now also this works:

using Plots
plotlyjs()

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