plotly.py
plotly.py copied to clipboard
on_click method doesn't work
I'm running the following code-snippet with Python3.7. The web-browser (Chrome) is opening and showing a scatter plot as expected. The problem is, when I click on the scatter points, the update_point method is not invoked. Am I doing something wrong?
import plotly.graph_objects as go
import numpy as np
np.random.seed(1)
x = np.random.rand(100)
y = np.random.rand(100)
f = go.FigureWidget([go.Scatter(x=x, y=y, mode='markers')])
scatter = f.data[0]
colors = ['#a3a7e4'] * 100
scatter.marker.color = colors
scatter.marker.size = [10] * 100
f.layout.hovermode = 'closest'
# create our callback function
def update_point(trace, points, selector):
c = list(scatter.marker.color)
s = list(scatter.marker.size)
for i in points.point_inds:
c[i] = '#bae2be'
s[i] = 20
with f.batch_update():
scatter.marker.color = c
scatter.marker.size = s
scatter.on_click(update_point)
f.show()
I also encountered this problem on 'Brave' web-browser with on_click and on_hover methods.
Hi ! I add the same problem and it comes from the f.show()
line. Looks like the view created by show()
does not relay callback functions. If you simply call f
instead (or IPython.display.display(f)
), the interactivity is available.
@ngilardiCBT IPython.display.display(f)
saved my day thanks
f
or IPython.display.display(f)
not work for me in jupyter notebook.
It gave me the following information:
Version: Python 3.7.6 Version: Plotly 5.13.0
FigureWidget({
'data': [{'marker': {'color': [#a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4,
#a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4,
#a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4,
#a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4,
#a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4,
#a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4,
#a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4,
#a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4,
#a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4,
#a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4,
#a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4,
#a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4,
#a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4,
#a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4,
#a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4,
#a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4,
#a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4,
#a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4,
#a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4,
#a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4, #a3a7e4],
'size': [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10]},
'mode': 'markers',
'type': 'scatter',
'uid': '16e8f15c-9320-434f-b17d-67febdfe01a2',
'x': array([4.17022005e-01, 7.20324493e-01, 1.14374817e-04, 3.02332573e-01,
1.46755891e-01, 9.23385948e-02, 1.86260211e-01, 3.45560727e-01,
3.96767474e-01, 5.38816734e-01, 4.19194514e-01, 6.85219500e-01,
2.04452250e-01, 8.78117436e-01, 2.73875932e-02, 6.70467510e-01,
4.17304802e-01, 5.58689828e-01, 1.40386939e-01, 1.98101489e-01,
8.00744569e-01, 9.68261576e-01, 3.13424178e-01, 6.92322616e-01,
8.76389152e-01, 8.94606664e-01, 8.50442114e-02, 3.90547832e-02,
1.69830420e-01, 8.78142503e-01, 9.83468338e-02, 4.21107625e-01,
9.57889530e-01, 5.33165285e-01, 6.91877114e-01, 3.15515631e-01,
6.86500928e-01, 8.34625672e-01, 1.82882773e-02, 7.50144315e-01,
9.88861089e-01, 7.48165654e-01, 2.80443992e-01, 7.89279328e-01,
1.03226007e-01, 4.47893526e-01, 9.08595503e-01, 2.93614148e-01,
2.87775339e-01, 1.30028572e-01, 1.93669579e-02, 6.78835533e-01,
2.11628116e-01, 2.65546659e-01, 4.91573159e-01, 5.33625451e-02,
5.74117605e-01, 1.46728575e-01, 5.89305537e-01, 6.99758360e-01,
1.02334429e-01, 4.14055988e-01, 6.94400158e-01, 4.14179270e-01,
4.99534589e-02, 5.35896406e-01, 6.63794645e-01, 5.14889112e-01,
9.44594756e-01, 5.86555041e-01, 9.03401915e-01, 1.37474704e-01,
1.39276347e-01, 8.07391289e-01, 3.97676837e-01, 1.65354197e-01,
9.27508580e-01, 3.47765860e-01, 7.50812103e-01, 7.25997985e-01,
8.83306091e-01, 6.23672207e-01, 7.50942434e-01, 3.48898342e-01,
2.69927892e-01, 8.95886218e-01, 4.28091190e-01, 9.64840047e-01,
6.63441498e-01, 6.21695720e-01, 1.14745973e-01, 9.49489259e-01,
4.49912133e-01, 5.78389614e-01, 4.08136803e-01, 2.37026980e-01,
9.03379521e-01, 5.73679487e-01, 2.87032703e-03, 6.17144914e-01]),
'y': array([0.3266449 , 0.5270581 , 0.8859421 , 0.35726976, 0.90853515, 0.62336012,
0.01582124, 0.92943723, 0.69089692, 0.99732285, 0.17234051, 0.13713575,
0.93259546, 0.69681816, 0.06600017, 0.75546305, 0.75387619, 0.92302454,
0.71152476, 0.12427096, 0.01988013, 0.02621099, 0.02830649, 0.24621107,
0.86002795, 0.53883106, 0.55282198, 0.84203089, 0.12417332, 0.27918368,
0.58575927, 0.96959575, 0.56103022, 0.01864729, 0.80063267, 0.23297427,
0.8071052 , 0.38786064, 0.86354185, 0.74712164, 0.55624023, 0.13645523,
0.05991769, 0.12134346, 0.04455188, 0.10749413, 0.22570934, 0.71298898,
0.55971698, 0.01255598, 0.07197428, 0.96727633, 0.56810046, 0.20329323,
0.25232574, 0.74382585, 0.19542948, 0.58135893, 0.97001999, 0.8468288 ,
0.23984776, 0.49376971, 0.61995572, 0.8289809 , 0.15679139, 0.0185762 ,
0.07002214, 0.48634511, 0.60632946, 0.56885144, 0.31736241, 0.98861615,
0.57974522, 0.38014117, 0.55094822, 0.74533443, 0.66923289, 0.26491956,
0.06633483, 0.3700842 , 0.62971751, 0.21017401, 0.75275555, 0.06653648,
0.2603151 , 0.80475456, 0.19343428, 0.63946088, 0.52467031, 0.92480797,
0.26329677, 0.06596109, 0.73506596, 0.77217803, 0.90781585, 0.93197207,
0.01395157, 0.23436209, 0.61677836, 0.94901632])}],
'layout': {'hovermode': 'closest', 'template': '...'}
})
Hi - we are tidying up stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for a while, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. If you'd like to submit a PR, we'd be happy to prioritize a review, and if it's a request for tech support, please post in our community forum. Thank you - @gvwilson