Update histogram based on hoverdata in map

Hello i’m new on dash and currently i’m trying to create an histogram which is updated based on hoverpoints on a map.
Can you help me.

Hey @ramatoulaye,
I’m not sure that’s possible. You can update histograms and other graphs by clicking on the markers on the map. But I don’t think you can connect a callback to a mouse hovering over a marker.

ok thanks. So I have done this

dcc.Graph(id=‘Graph3’,hoverData={‘points’: [{‘customdata’: ‘Japan’}]}

Here is the function that did the discretisation of a variable in my dataframe.
I want it to put specific intervals as input to my histogram plot.

def discretisation_arbre(df_filtre, variable, cible): #df_filtre = base filtrée avec substance, distributeur et année.
# construction du modèle
tree_model = DecisionTreeClassifier(max_depth=2)
tree_model.fit(df_filtre[variable].to_frame(), df_filtre[cible])

#construction de la probabilité de chaque individu d'apartenir à la modalité correspondante
df_filtre["prob_tree"]=tree_model.predict_proba(df_filtre[variable].to_frame())[:,1]
# discretisation
maximum= df_filtre.groupby(["prob_tree"])[variable].max()
discretisation = sorted([x for x in maximum])
discretisation[0:0] = [0]
return discretisation

def create_hist(pra_select, discretisation): #base_select = base du pra, discretisation = discretisation de la substance et du distributeur
bins = discretisation #intervalles pour cette substance et ce distributeur
return {
“data”: [{
“type”: “Histogram”,
“x”:pra_select[‘QuantiteSubstanceKg’],
“xbins”:dict(start=0.0,end=148.0),
“marker”:dict(color=‘rgb(0, 0, 100)’),
“autobinx” : False}
],
“layout”: dict(
title=‘Histogram Frequency Counts’)
}
Here is the function used to create the figure. I have a problem with that because plotly choose itself the bounds but i need to specify it with the result my previous function.

How can i do it?

After i have used the Graph3 with is the map to hover over markers.
Is this correct?
@app.callback(
dash.dependencies.Output(‘Graph6’,‘figure’),
[dash.dependencies.Input(‘Graph3’, ‘hoverData’),
dash.dependencies.Input(‘Subst_dropdown’, ‘value’),
dash.dependencies.Input(‘Dist_dropdown’, ‘value’)])
def update_hist_3(hoverData, Substance_selection, Distributor_selection):
df_filtre = df_2017[df_2017[‘Substance’] == Substance_selection]
df_filtre = df_filtre[df_filtre[‘Distributeur’] == Distributor_selection]
discretisation = discretisation_arbre(df_filtre, variable = ‘QuantiteSubstanceKg’, cible=‘code_pra’) #sur subst, distr et ts les pras
dff = df_2017[df_2017[‘code_pra’] == hoverData[‘points’][0][‘customdata’]] #1 seul pra
dff = dff[dff[‘Substance’] == Substance_selection]
dff = dff[dff[‘Distributeur’] == Distributor_selection]
val_c = dff[‘code_pra’].value_counts().reset_index()
val_c.columns=[‘code_pra’,‘occ_pra’]
df_merge = pd.merge(val_c, dff, on=‘code_pra’)
if(df_merge[‘occ_pra’] <= 4):
return{‘data’:[]}
else:
return create_hist(df_merge, discretisation)

Thanks you.