# How to create a plot with slider bars

**URL:** <https://discourse.julialang.org/t/how-to-create-a-plot-with-slider-bars/74213>\
**Category:** New to Julia\
**Tags:** plotting, makie\
**Created:** [January 7, 2022, 7:50pm UTC](https://discourse.julialang.org/t/how-to-create-a-plot-with-slider-bars/74213 "2022-01-07T19:50:55Z")\
**Posts on this page:** 8\
**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 7, 2022, 7:50pm UTC](https://discourse.julialang.org/t/how-to-create-a-plot-with-slider-bars/74213/1 "2022-01-07T19:50:55Z")

</div>

I have a function that creates plots after taking in two arguments

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

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

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [January 7, 2022, 8:20pm UTC](https://discourse.julialang.org/t/how-to-create-a-plot-with-slider-bars/74213/2 "2022-01-07T20:20:35Z")

</div>

with Makie.  
This case is just the first example here:  
[https://makie.juliaplots.org/stable/examples/layoutables/slider/index.html#slider](https://makie.juliaplots.org/stable/examples/layoutables/slider/index.html#slider)

---

<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 7, 2022, 10:38pm UTC](https://discourse.julialang.org/t/how-to-create-a-plot-with-slider-bars/74213/3 "2022-01-07T22:38:15Z")

</div>

@lazarusA Going off the first example, when I run the following code:

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

```

The plot does not have sliders. Instead, I have the error, `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, 4:28pm UTC](https://discourse.julialang.org/t/how-to-create-a-plot-with-slider-bars/74213/4 "2022-01-08T16:28:16Z")

</div>

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 ⚡](https://pluton.lee-phillips.org/sliders/uiDemoP2.html)

---

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [February 7, 2023, 2:34pm UTC](https://discourse.julialang.org/t/how-to-create-a-plot-with-slider-bars/74213/5 "2023-02-07T14:34:52Z")

</div>

> [@lazarusA](#):
>
> with Makie.  
> This case is just the first example here:  
> [https://makie.juliaplots.org/stable/examples/layoutables/slider/index.html#slider](https://makie.juliaplots.org/stable/examples/layoutables/slider/index.html#slider)

This link is broken. Could you be so kind and provide another Link?

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [February 7, 2023, 2:41pm UTC](https://discourse.julialang.org/t/how-to-create-a-plot-with-slider-bars/74213/6 "2023-02-07T14:41:24Z")

</div>

@ellocco  
[https://docs.makie.org/stable/examples/blocks/slider/index.html#slider](https://docs.makie.org/stable/examples/blocks/slider/index.html#slider)

---

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [February 7, 2023, 2:58pm UTC](https://discourse.julialang.org/t/how-to-create-a-plot-with-slider-bars/74213/7 "2023-02-07T14:58:50Z")

</div>

> [@lazarusA](#):
>
> [Page Redirection](https://docs.makie.org/stable/examples/blocks/slider/index.html#slider)

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

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

```

---

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [February 7, 2023, 5:45pm UTC](https://discourse.julialang.org/t/how-to-create-a-plot-with-slider-bars/74213/8 "2023-02-07T17:45:52Z")

</div>

Just now I managed also to get it into operation, see:  
[OpenGL/GLFW error building GLMakie](https://discourse.julialang.org/t/opengl-glfw-error-building-glmakie/47598/10)
