Here is an adaptation of that PlotlyJS example (Click events in Julia) but using just the Plots.jl
interface calls. I’m assuming the plotlyjs
backend for Plots.jl
is set up. Hope it helps.
import Plots
import Plots: KW
Plots.plotlyjs()
color_vec = [fill("blue",10), fill("red",10)]
pl = Plots.scatter(
1:10,
rand(10),
extra_kwargs = KW(
:series => KW(
:showlegend => true,
:mode => "lines+markers+text",
:name => "blue-green",
:marker => KW(:color => color_vec[1], :symbol => "circle", :size => 10),
:line => KW(:dash => "dash", :width => 2),
),
)
)
Plots.scatter!(pl,
1:10,
rand(10),
extra_kwargs = KW(
:series => KW(
:name => "red-purple",
:mode => "lines+markers+text",
:marker => KW(:color => color_vec[2], :symbol => "circle", :size => 10)
),
)
)
display(pl)
p = Plots.backend_object(pl)
using Plots.PlotlyJS.WebIO
on(p["click"]) do data
color_vec_alt = [fill("green",10), fill("purple",10)]
symbols = [fill("circle", 10), fill("circle", 10)]
for point in data["points"]
color_vec_alt[point["curveNumber"] + 1][point["pointIndex"] + 1] = "gold"
symbols[point["curveNumber"] + 1][point["pointIndex"] + 1] = "star"
end
Plots.PlotlyJS.restyle!(p, marker_color=color_vec_alt, marker_symbol=symbols)
end