FigureWidget Histogram Click event

I am trying to see if it’s possible to use on_click with a histogram trace (with clickmode=‘select’), to get the id of the histogram bin selected and (even better) the indices of the points in the bin selected. This doesn’t seem to work in the example below, the points_inds field is empty. NB: this works with dragmode=‘select’, but not with clickmode=‘select’.
Any help appreciated (indentation lost when copying and pasting code).

import pandas as pd
import numpy as np
import plotly.graph_objects as go
from ipywidgets import widgets


fig = go.FigureWidget(
go.Histogram(x=col1, marker={‘color’: ‘blue’},
selected={‘marker’: {‘color’: ‘firebrick’}}, unselected={‘marker’: {‘opacity’: 0.3,‘color’:‘blue’}}

yaxis={‘title’: ‘Count’, ‘domain’: [0, 1]},

def update_color(trace, points, state):
# Update histogram plot selection[0].selectedpoints = points.point_inds[0].on_click(update_color)

fig[0].selectedpoints # returns nothing with ‘clickmode’, returns item indices in selected bin as expected, with ‘dragmode’ (and ‘on_selection’ instead of ‘on_click’ in the callback registration)

1 Like