运行以下笔记本单元
%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()
产量`
目前可能的修复
function makie2image(fig)
buf = IOBuffer()
Makie.backend_show(GLMakie.GLBackend(), buf, MIME("image/png"), fig.scene)
pyimport("IPython").display.Image(pybytes(buf.data))
end
用作:
Main.makie2image(Main.plot_something())
上述答案对我不起作用。相反,我必须使用更新的 JuliaCall 库
from juliacall import Main as jl
# Install the Makie package. This only needs to be run once then Main reloaded
import juliapkg
juliapkg.add("GLMakie", uuid="e9467ef8-e4e7-5192-8a1a-b1aee30e663a")
# Import GLMAkie into the Julia session
jl.seval("using GLMakie")
import numpy as np
x = np.linspace(0.1, 10, 30)
f = lambda x: x**2 * np.sin(x + 1/x)
y = f(x)
fig, ax, lns = jl.lines(x, y, label="Simple function")
jl.axislegend(position=jl.seval(':lt'))
fig
不幸的是,这失去了酷炫的
%%julia
细胞魔法
上述答案对我不起作用。相反,我必须使用更新的 JuliaCall 库
from juliacall import Main as jl
# Install the Makie package. This only needs to be run once then Main reloaded
import juliapkg
juliapkg.add("GLMakie", uuid="e9467ef8-e4e7-5192-8a1a-b1aee30e663a")
# Import GLMAkie into the Julia session
jl.seval("using GLMakie")
import numpy as np
x = np.linspace(0.1, 10, 30)
f = lambda x: x**2 * np.sin(x + 1/x)
y = f(x)
fig, ax, lns = jl.lines(x, y, label="Simple function")
jl.axislegend(position=jl.seval(':lt'))
fig
不幸的是,这失去了酷炫的
%%julia
细胞魔法