Makie - How to make interactive plots with custom Axis3?

I’m using WGLMakie in a Pluto notebook. Whenever I create a 3D plot with an implicit axis, for instance by using meshscatter(x, y), Makie creates an interactive plot, meaning I can rotate, pan, and zoom it using the mouse.

But if I want to customize the axis properties, I think I need to create my own Axis3 object and use the mutating variant of the plot function on it: meshscatter!(axis, x, y). But this creates a static plot, that is no longer interactive.

How can I create an interactive plot with a custom Axis3?

What’s minimal reproducible code that gives you a static plot where you’d expect an interactive one?

It took me a while, but I figured out a way to reproduce the bug. It’s a strange bug, probably related to some internal state in the notebook.

In any case, a minimal example is the following:

# ╔═╡ 2157da26-5c73-11ef-21d8-0b97730c2f8c
begin
	using JSServe, WGLMakie
	Page()
end

# ╔═╡ 344f87ac-e6d3-419c-a3d6-39aca7867146
let
	# figure with automatic axis
	fig = Figure()
	meshscatter(fig[1,1], Point3f(0,0,0), marker=Rect3f([0,0,0], [1,1,1]))
	fig
end

# ╔═╡ 3032020e-210d-44fc-871e-70816ada859e
let
	# figure with manual axis
	fig = Figure()
	axis = Axis3(fig[1,1])
	meshscatter!(axis, Point3f(0,0,0), marker=Rect3f([0,0,0], [1,1,1]))
	fig
end

Instructions:

  1. copy and paste the text above into a new Pluto notebook, it should create 3 cells;
  2. save the notebook with a name, you will need to reload it later;
  3. execute the cells: both figures are interactive, meaning that the mouse can rotate the cube;
  4. refresh the browser window, or go back to the Pluto index and reopen the notebook (that is still running in the background): the first figure is still interactive, but the second one is either not shown, or is not interactive;
  5. go back to the Pluto index, stop the notebook by clicking on the (x) beside its name, and run it again: both cells work again.
1 Like

Sadly, WGLMakie doesn’t support Pluto saving/reloading right now :frowning:

Btw, JSServe got renamed to Bonito, so you should remove JSServe from your project :wink:

Oh, I see. That’s ok. But I hope they add a warning when you try to reload a Pluto notebook, even just a plain JS alert box with “Please stop and restart this notebook,” because it’s not obvious, I lost a lot of time trying to figure out what I was doing wrong :slightly_frowning_face:

As for the JSServe, I have no idea what it is, because I’m new to all of this, I just followed the official instructions here. What do you think I should write instead? Can I just import WGLMakie, or do I still need to create some kind of Page object in the first Pluto cell, as they say on there?

Oh damn, these are not the official instructions but some very old ones…
We’ve been trying to hunt them down, but I guess there are still some old ones.
https://docs.makie.org/ is the official documentation!

1 Like

Yes, I’ve been using those docs, but for some reason when I searched how to use it in Pluto, I ended up in that other site. Anyways, I see I can just import the package and use it, no need to explicitly configure the server. Nice, thanks!