# Update xlims in interactive GLMakie

**URL:** <https://discourse.julialang.org/t/update-xlims-in-interactive-glmakie/93825>\
**Category:** Visualization\
**Tags:** makie, observables\
**Created:** [January 31, 2023, 4:53pm UTC](https://discourse.julialang.org/t/update-xlims-in-interactive-glmakie/93825 "2023-01-31T16:53:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mreichMPI-BGC](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mreichmpi-bgc/32/43775_2.png) [@mreichMPI-BGC](https://discourse.julialang.org/u/mreichMPI-BGC)\
**Post date:** [January 31, 2023, 4:53pm UTC](https://discourse.julialang.org/t/update-xlims-in-interactive-glmakie/93825/1 "2023-01-31T16:53:13Z")

</div>

I have the question how to make xlims and ylims update automatically when an Observable changes.  
For instance:

```julia
x=1:10 |> collect |> Observable
fig, ax, plt = scatter(x, @lift($x .^ 2))
fig

```

Updating `x` does not lead to updating the xlims and ylims, unless I call `autolimits!(ax)`

I tried also

```julia
on(x) do i
     autolimits!(ax)
end

```

but this caused  
`ERROR: MethodError: no method matching (::var"#183#184")(::Vector{Int64})`

Thanks!

EDIT:  
Ok, it seemed there was another wrong `on(x)` defined…  
This works

```julia
z=1:10 |> collect |> Observable
fig, ax, plt = scatter(z, @lift($z .^ 2));
on(z) do i
     autolimits!(ax)
end
fig

```

Still, is this “correct”?

---

<div class="post-metadata">

**Author:** ![mkoculak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkoculak/32/28310_2.png) [@mkoculak](https://discourse.julialang.org/u/mkoculak)\
**Post date:** [January 31, 2023, 7:17pm UTC](https://discourse.julialang.org/t/update-xlims-in-interactive-glmakie/93825/2 "2023-01-31T19:17:46Z")

</div>

Yes, that’s the way to go.

---

<div class="post-metadata">

**Author:** ![mreichMPI-BGC](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mreichmpi-bgc/32/43775_2.png) [@mreichMPI-BGC](https://discourse.julialang.org/u/mreichMPI-BGC)\
**Post date:** [January 31, 2023, 9:35pm UTC](https://discourse.julialang.org/t/update-xlims-in-interactive-glmakie/93825/3 "2023-01-31T21:35:19Z")

</div>

A maybe short follow up question. Am I right, that this does (still?) not work with AlgebraofGraphics?

I have tried to `@lift` at various levels without success. Outside everything for instance I get:

```julia
plt = @lift(data(df) * ... ) # Code not shown
julia> draw(plt)
ERROR: MethodError: no method matching draw(::Observable{Layers}) 

```

Thanks!

---

<div class="post-metadata">

**Author:** ![mreichMPI-BGC](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mreichmpi-bgc/32/43775_2.png) [@mreichMPI-BGC](https://discourse.julialang.org/u/mreichMPI-BGC)\
**Post date:** [January 31, 2023, 9:42pm UTC](https://discourse.julialang.org/t/update-xlims-in-interactive-glmakie/93825/4 "2023-01-31T21:42:57Z")

</div>

Sorry, continued to try…  
This seems to work:  
`@lift(display($plt))`  
Are there any guides/rules at which level the `@lift` should be applied. E.g. in the post above it can be inside `scatter`.

---

<div class="post-metadata">

**Author:** ![mkoculak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkoculak/32/28310_2.png) [@mkoculak](https://discourse.julialang.org/u/mkoculak)\
**Post date:** [January 31, 2023, 10:14pm UTC](https://discourse.julialang.org/t/update-xlims-in-interactive-glmakie/93825/5 "2023-01-31T22:14:31Z")

</div>

So in general you can lift almost any parameter passed into specific plot functions in GLMakie.  
However, `draw()` is a function specific to Algebra of Graphics and it does not seem to have this implemented.

You should in general lift those things you want to change after you plotted the figure, e.g. data points or colors.  
Can you interactively change anything in the `plt` from your last post? Cause my guess would be that it would not work, but I also have no experience with AoG.

---

<div class="post-metadata">

**Author:** ![mreichMPI-BGC](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mreichmpi-bgc/32/43775_2.png) [@mreichMPI-BGC](https://discourse.julialang.org/u/mreichMPI-BGC)\
**Post date:** [January 31, 2023, 10:49pm UTC](https://discourse.julialang.org/t/update-xlims-in-interactive-glmakie/93825/6 "2023-01-31T22:49:51Z")

</div>

Thanks - I created a new topic with a MWE…: [Interactive Menu with AlgebraOfGraphics / GLMakie](https://discourse.julialang.org/t/interactive-menu-with-algebraofgraphics-glmakie/93842)
