I have the question how to make xlims and ylims update automatically when an Observable changes.
For instance:
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
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
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”?
Yes, that’s the way to go.
1 Like
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:
plt = @lift(data(df) * ... ) # Code not shown
julia> draw(plt)
ERROR: MethodError: no method matching draw(::Observable{Layers})
Thanks!
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
.
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.