Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
Want to display HoverTool tooltip data with the TapTool in bokeh

I am new to python and want to make an interactive chart with a dataset given in class. I want to be able to simply display the data associated with the point I select with the TapTool in Bokeh. The data is too dense to jsut simply use the hovertool though. It seems the hovertool did not require javascript, but apparently getting the tap tool requires knowing a whole other coding language. I am not familiar with python as it is, so adding a javascript callback is making things a bit complicated.

Right now I have this figure plotted with my dataframe using data from the California Housing dataset from sci-kit. I also have the US_states sampledata from bokeh to plot too.

from bokeh.layouts import layout
from bokeh.plotting import figure, show, output_file
from bokeh.models import Circle, Div, ColumnDataSource, CustomJS, MultiChoice, HoverTool, LinearColorMapper, ColorBar
from bokeh.io import output_notebook
from bokeh.sampledata import us_states
from bokeh.transform import transform
from bokeh.models.tools import *

#US state sample data
us_states = us_states.data.copy()
us_states = us_states["CA"]



#Creating figure and adding california basemap
color = LinearColorMapper(palette = 'Viridis256',
                      low = df.MedInc.min(),
                      high = df.MedInc.max())
color2 = LinearColorMapper(palette = 'Inferno256',
                      low = df.price.min(),
                      high = df.price.max())

cal = figure(title = "California Housing Data Geographic Distribution",
         plot_width = 1000)

cal.circle('Longitude','Latitude',source = geo_source, 
       color= transform('MedInc', color),size =2,
       alpha = 0.2,legend_label = "Median Income")

cal.circle('Longitude','Latitude',source = geo_source, 
       color= transform('price', color2),size =1,
       alpha = 0.2,legend_label = "House Price")



 color_bar = ColorBar(color_mapper = color,
                 label_standoff = 14,
                 location = (0,0),
                 title = 'Median Income')

 color_bar2 = ColorBar(color_mapper = color2,
                 label_standoff = 14,
                 location = (0,0),
                 title = 'House Price')

 cal.add_layout(color_bar,'right')
 cal.add_layout(color_bar2,'right')

 cal.legend.location = "top_right"
 cal.legend.click_policy="hide"
                      

I have no clue what to write for the JS callback for the TapTool though since I'm not really sure how it works, how the variables transfer, etc.

callback = CustomJS(args=dict(source=geo_source), code="""
//Insert JS code here
""")

taptool = TapTool(callback=callback)
geo_source.selected.js_on_change('indices', callback)
cal.add_tools(taptool)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

you should add figure to Tap event

plot.on_event(Tap, function)

and in function you can use indices to update your data/graph

def function():
    print(source.selected.indices)
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda