Plots.jl click input
Click somewhere on this graph:
xxxxxxxxxxxxxxxxxxxx [5,5] x0 plotclicktracker(linepoint(x0))5
5
xxxxxxxxxxx0linepoint (generic function with 1 method)xxxxxxxxxxfunction linepoint(click_coordinate) p = plot(1:10) scatter!(p, click_coordinate[1:1], click_coordinate[2:2])endWhy is this special? Because normally, the input (@bind) and output live in two separate cells:
xxxxxxxxxxxxxxxxxxxx x html"<input type=range>"missingxxxxxxxxxxsqrt(x)But in our interactive plot, the input and output are inside the same cell. To achieve this, we need a couple of tricks: a click tracker wrapper, a self-referencing cell and the @initially macro. Let's talk about those one by one:
Click tracker
TUTORIAL WORK IN PROGRESS
xxxxxxxxxxCOOL_PLOT (generic function with 1 method)xxxxxxxxxxfunction COOL_PLOT(q0) p = plot(1:10) scatter!(p, q0[1:1], q0[2:2]) return pendThe third step is to write a function that:
takes a click coordinate (a vector
[x, y]) as input, andreturns a plot.
It's up to you to use this coordinate in a creative way!
xxxxxxxxxxNecessary functions
You can copy these cells into your notebook by selecting them (start dragging a selection rectangle from inbetween two cells), and dragging them into another notebook.
xxxxxxxxxxplotclicktracker (generic function with 1 method)xxxxxxxxxxintially_function (generic function with 1 method)xxxxxxxxxxYou can also use ingredients to load this notebook into another notebook.
xxxxxxxxxxPackages
(We only need Plots.jl)
xxxxxxxxxxxxxxxxxxxxbegin import Pkg Pkg.activate(mktempdir()) Pkg.add([ Pkg.PackageSpec(name="Plots", version="1.6-1"), ]) using Plotsend