I am learning how to create plots with slider bars. Here is my code based off the first example of
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
plot(n, 1 .- log_delta_xi.^2/6, linecolor = :green, label="n = $n")
When I run this, it gives
UndefVarError: plot not defined. What am I missing here?
I guess GLMakie doesn’t export a
plot function. The example uses
Ok. I looked at
PlutoUI but where in the code do you set up the sliders? How can I adapt this with my code to avoid the same
PlutoUI is a set of functions that wrap HTML input controls to make it easier to create sliders, etc. in a Pluto notebook. You can bind any variable to the slider, and refer to the variable in a plot command, or anywhere else. It won’t solve your problem of using an undefined function. See my notebook for example code.
@LeePhillips I got the sliders to work, thanks for sharing your notebook!
There is still a lot about Pluto that confuses me, but we all start somewhere I suppose.
How do you add the value next to the slider by the way?
And how do you set a default value on the slider?
To display the value of the slider next to it, just interpolate the variable that it’s bound to right in the Markdown:
md"Time: $tslider $t Color: $ccpicker Line style: $lspicker"
Play with Pluto a bit more and it will click, be patient. It’s fun!
Most controls accept a
default argument. I suggest looking through the sample notebooks that are provided when you run Pluto. They’re quite instructive!
Agreed! re: PlutoUI, their
Slider also accepts a
show_value keyword, in addition to
default, which can be pretty handy
Sort of random, but are you studying stellar physics by any chance
@CentraCep? I haven’t seen polytropes in a hot minute!
My research area is solar physics, but I completed a course in stellar physics last semester. The program related to this thread was written for fun and to practice Julia, while using something I learned from the class!
Cool! Using Julia for some of my own astro related stuff was how I started practicing with Julia as well. Hope you’re enjoying it!