How to make GLMakie "open interactive windows" from Jupyter

I am trying to reproduce a simple plot with a slider from the Makie docs.

I read in the Makie basic tutorial

To see the output of plotting commands when using CairoMakie, we recommend you either use an IDE which supports png or svg output, such as VSCode, Atom/Juno, Jupyter, Pluto, etc.,

So I pasted the slider example code into a Jupyter notebook:

using CairoMakie

f = Figure()
Axis(f[1, 1], limits = (0, 1, 0, 1))

rs_h = IntervalSlider(f[2, 1], range = LinRange(0, 1, 1000),
    startvalues = (0.2, 0.8))
rs_v = IntervalSlider(f[1, 2], range = LinRange(0, 1, 1000),
    startvalues = (0.4, 0.9), horizontal = false)

labeltext1 = lift(rs_h.interval) do int
    string(round.(int, digits = 2))
end
Label(f[3, 1], labeltext1, tellwidth = false)
labeltext2 = lift(rs_v.interval) do int
    string(round.(int, digits = 2))
end
Label(f[1, 3], labeltext2,
    tellheight = false, rotation = pi/2)

points = rand(Point2f, 300)

# color points differently if they are within the two intervals
colors = lift(rs_h.interval, rs_v.interval) do h_int, v_int
    map(points) do p
        (h_int[1] < p[1] < h_int[2]) && (v_int[1] < p[2] < v_int[2])
    end
end

scatter!(points, color = colors, colormap = [:black, :orange], strokewidth = 0)

f

This causes the cell to output the following static image.

Needless to say, I want to be able to drag around the sliders. So, I went back to the basic tutorial (same link as above) and read the following:

GLMakie can open interactive windows, or alternatively display bitmaps inline if Makie.inline!(true) is called.

I thought: “Aha, so if I use the GLMakie backend instead of CairoMakie, I can get Makie to open an interactive window! That’s what I need. Seems weird that the documentation slider example would use CairoMakie, but let’s try it.”

So, I changed the code above to the following:

using GLMakie
GLMakie.activate!()
Makie.inline!(false)  # Probably unnecessary?

f = Figure()
# ...

but this produces the same, static figure as above, except with lower resolution:

(The resolution is actually quite bad—look at the decimal point in 0.4.)

Questions:

  • How do I actually get Makie to open the promised “interactive windows”?
  • Can it be done in CairoMakie, or do I have to use GLMakie?
  • If it’s the latter, then why does the slider example in the documentation use CairoMakie at all?
  • try display(f)
  • no, you need to use GLMakie
  • because it looks better, and won’t be interactive on the web anyways

For some reason on my Julia 1.6.1 installation I get UndefVarError: Point2f not defined using the script in the OP. This error goes away in Julia 1.6.2 or by changing Point2f to Point2f0.

try display(f)

This works, thank you.

because it looks better, and won’t be interactive on the web anyways

I’m not a developer, but isn’t this out of line with good documentation practice? It seems like a minimal requirement for example code in the documentation is that it actually works as described, with aesthetic considerations secondary.

To someone new to Makie, the fact that one page says “CairoMakie doesn’t do interactivity” and then another page uses CairoMakie for an interactive plot is just confusing. The two pages contradict each other, and it’s not obvious which one is wrong.

To someone new to Makie, the fact that one page says “CairoMakie doesn’t do interactivity” and then another page uses CairoMakie for an interactive plot is just confusing. The two pages contradict each other, and it’s not obvious which one is wrong.

PRs to improve the documentation are very welcome :slight_smile: