How to get Julia Makie Output in python Jupiter notebook?

Viewed 90

Running the following notebook cells

%load_ext julia.magic
%%julia
using GLMakie 

function plot_something()
    odeSol(x,y) = Point(-x, 2y)             # x'(t) = -x, y'(t) = 2y
    fig = Figure(resolution =(400,400))
    ax = Axis(fig)
    streamplot!(ax, odeSol, -2..2, -2..2, colormap = :plasma, 
        gridsize= (32,32), arrow_size = 0.07)
    fig[1,1] = ax
    fig
end
from julia import Main
Main.show_something()

yields `<PyCall.jlwrap Scene (400px, 400px):' rather than the hoped for figure. Any good fixes?

1 Answers

A possible fix for now

function makie2image(fig)
    buf = IOBuffer()
    Makie.backend_show(GLMakie.GLBackend(), buf, MIME("image/png"), fig.scene)
    pyimport("IPython").display.Image(pybytes(buf.data))
end

Used as:

Main.makie2image(Main.plot_something())
Related