I have a function that creates plots after taking in two arguments
function plotLaneEmden(log_delta_xi=-4, n=3)
plot(n, 1 .- log_delta_xi.^2/6, linecolor = :green, label="n = $n")
xlabel!("ξ")
ylabel!("θ")
end
I would like to make the plot more interactive by adding sliders to change n
and log_delta_xi
. In Python, this can be done with ipywidgets
:
from ipywidgets import interact, interactive, fixed, interact_manual, FloatSlider
import ipywidgets as widgets
interact(plotLaneEmden,
n=FloatSlider(min=0, max=4.99, step=0.01, value=3, continuous_update=False),
log_delta_xi=FloatSlider(min=-6, max=0.1, step=0.01, value=-2, continuous_update=False));
Is there an analogous way to do this in julia?
@lazarusA Going off the first example, when I run the following code:
function plotLaneEmden(log_delta_xi=-4, n=3)
fig = Figure()
ax = Axis(fig[1, 1])
sl_x = Slider(fig[2, 1], range = 0:0.01:4.99, startvalue = 3)
sl_y = Slider(fig[1, 2], range = -6:0.01:0.1, horizontal = false, startvalue = -2)
point = lift(sl_x.value, sl_y.value) do n, log_delta_xi
Point2f(n, log_delta_xi)
end
plot(n, 1 .- log_delta_xi.^2/6, linecolor = :green, label="n = $n")
xlabel!("ξ")
ylabel!("θ")
end
The plot does not have sliders. Instead, I have the error, UndefVarError: plot not defined
. What am I missing here?
If you don’t mind your plot being displayed inside a web page, you can use Pluto with PlutoUI. It’s quite simple, and works with any plotting package. I have a live demonstration of an interactive plot made with Pluto at ⚡ Pluto.jl ⚡
This link is broken. Could you be so kind and provide another Link?
Thanks for the fast reply!!!
Is there an advice for ubuntu-users to get started?
This example complains about issues during creation of an OpenGL window
:
libGL error: failed to load driver: swrast
┌ Warning: GLFW couldn't create an OpenGL window.
│ This likely means, you don't have an OpenGL capable Graphic Card,
│ or you don't have an OpenGL 3.3 capable video driver installed.
│ Have a look at the troubleshooting section in the GLMakie readme:
│ https://github.com/MakieOrg/Makie.jl/tree/master/GLMakie#troubleshooting-opengl.
└ @ GLMakie ~/.julia/packages/GLMakie/N16Fq/src/screen.jl:229
ERROR: LoadError: GLFWError (VERSION_UNAVAILABLE): GLX: Failed to create context: GLXBadFBConfig
Just now I managed also to get it into operation, see:
OpenGL/GLFW error building GLMakie