# "Plot not defined" when attempting to add slider bars

**URL:** <https://discourse.julialang.org/t/plot-not-defined-when-attempting-to-add-slider-bars/74251>\
**Category:** New to Julia\
**Tags:** makie\
**Created:** [January 8, 2022, 6:11pm UTC](https://discourse.julialang.org/t/plot-not-defined-when-attempting-to-add-slider-bars/74251 "2022-01-08T18:11:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![CentraCep](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/centracep/32/32454_2.png) [@CentraCep](https://discourse.julialang.org/u/CentraCep)\
**Post date:** [January 8, 2022, 6:11pm UTC](https://discourse.julialang.org/t/plot-not-defined-when-attempting-to-add-slider-bars/74251/1 "2022-01-08T18:11:23Z")

</div>

I am learning how to create plots with slider bars. Here is my code based off the first example of [this tutorial](https://makie.juliaplots.org/stable/examples/layoutables/slider/index.html#slider)

```julia
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

plotLaneEmden()

```

When I run this, it gives `UndefVarError: plot not defined`. What am I missing here?

---

<div class="post-metadata">

**Author:** ![LeePhillips](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leephillips/32/205514_2.png) [@LeePhillips](https://discourse.julialang.org/u/LeePhillips)\
**Post date:** [January 8, 2022, 6:32pm UTC](https://discourse.julialang.org/t/plot-not-defined-when-attempting-to-add-slider-bars/74251/2 "2022-01-08T18:32:44Z")

</div>

I guess GLMakie doesn’t export a `plot` function. The example uses `scatter!()`.

---

<div class="post-metadata">

**Author:** ![CentraCep](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/centracep/32/32454_2.png) [@CentraCep](https://discourse.julialang.org/u/CentraCep)\
**Post date:** [January 8, 2022, 7:01pm UTC](https://discourse.julialang.org/t/plot-not-defined-when-attempting-to-add-slider-bars/74251/3 "2022-01-08T19:01:35Z")

</div>

Ok. I looked at [PlutoUI](https://pluton.lee-phillips.org/sliders/uiDemoP2.html) but where in the code do you set up the sliders? How can I adapt this with my code to avoid the same `UndefVarError`?

---

<div class="post-metadata">

**Author:** ![LeePhillips](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leephillips/32/205514_2.png) [@LeePhillips](https://discourse.julialang.org/u/LeePhillips)\
**Post date:** [January 8, 2022, 7:16pm UTC](https://discourse.julialang.org/t/plot-not-defined-when-attempting-to-add-slider-bars/74251/4 "2022-01-08T19:16:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![CentraCep](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/centracep/32/32454_2.png) [@CentraCep](https://discourse.julialang.org/u/CentraCep)\
**Post date:** [January 9, 2022, 12:27am UTC](https://discourse.julialang.org/t/plot-not-defined-when-attempting-to-add-slider-bars/74251/5 "2022-01-09T00:27:14Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![LeePhillips](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leephillips/32/205514_2.png) [@LeePhillips](https://discourse.julialang.org/u/LeePhillips)\
**Post date:** [January 9, 2022, 12:43am UTC](https://discourse.julialang.org/t/plot-not-defined-when-attempting-to-add-slider-bars/74251/6 "2022-01-09T00:43:13Z")

</div>

To display the value of the slider next to it, just interpolate the variable that it’s bound to right in the Markdown:

```julia
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!

---

<div class="post-metadata">

**Author:** ![icweaver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/icweaver/32/45764_2.png) [@icweaver](https://discourse.julialang.org/u/icweaver)\
**Post date:** [January 10, 2022, 4:40am UTC](https://discourse.julialang.org/t/plot-not-defined-when-attempting-to-add-slider-bars/74251/7 "2022-01-10T04:40:22Z")

</div>

> [@LeePhillips](#):
>
> Pluto

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!

---

<div class="post-metadata">

**Author:** ![CentraCep](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/centracep/32/32454_2.png) [@CentraCep](https://discourse.julialang.org/u/CentraCep)\
**Post date:** [January 10, 2022, 5:36am UTC](https://discourse.julialang.org/t/plot-not-defined-when-attempting-to-add-slider-bars/74251/8 "2022-01-10T05:36:48Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![icweaver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/icweaver/32/45764_2.png) [@icweaver](https://discourse.julialang.org/u/icweaver)\
**Post date:** [January 10, 2022, 6:53pm UTC](https://discourse.julialang.org/t/plot-not-defined-when-attempting-to-add-slider-bars/74251/9 "2022-01-10T18:53:22Z")

</div>

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!
