# Plots and click events

**URL:** <https://discourse.julialang.org/t/plots-and-click-events/104253>\
**Category:** Visualization\
**Tags:** question, plots, pluto, plotlyjs\
**Created:** [September 26, 2023, 10:18am UTC](https://discourse.julialang.org/t/plots-and-click-events/104253 "2023-09-26T10:18:25Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [October 2, 2023, 1:20pm UTC](https://discourse.julialang.org/t/plots-and-click-events/104253/7 "2023-10-02T13:20:15Z")

</div>

Here is an adaptation of that PlotlyJS example ([Click events in Julia](https://plotly.com/julia/click-events/)) but using just the `Plots.jl` interface calls. I’m assuming the `plotlyjs` backend for `Plots.jl` is set up. Hope it helps.

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

```

---

_[View the full topic](https://discourse.julialang.org/t/plots-and-click-events/104253)._
