Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

328
Views
Use la ubicación ajustada de la herramienta de desplazamiento de bokeh en la devolución de llamada del evento CustomJS

En un cuaderno de Databricks, estoy trazando una curva usando bokeh. Quiero que el usuario pueda pasar el cursor sobre el gráfico, hacer que se ajuste a la curva y luego, mediante un clic del mouse, tener la capacidad de imprimir datos (x, y) para el punto de la curva que tiene su cursor. ajustado a.

Como verás a continuación, estoy a mitad de camino. La herramienta flotante permite que el cursor del usuario se ajuste a la curva, y la devolución de llamada de JS imprimirá los datos (x, y) en la ubicación del cursor en el gráfico al hacer clic con el mouse. El problema es que quiero que el (x, y) impreso no se corresponda con la ubicación del cursor (lo que está haciendo actualmente), sino con la ubicación en la curva a la que se ajusta la herramienta flotante. ¿Es posible obtener esa información desde la herramienta de desplazamiento hasta la devolución de llamada del evento?

 import bokeh.embed as bembed from bokeh import events from bokeh.io import output_file from bokeh.layouts import row from bokeh.models import CustomJS, Div from bokeh.plotting import figure from bokeh.models import HoverTool from bokeh.resources import CDN def display_event(div, attributes=[], style = 'float:left;clear:left;font_size=13px'): return CustomJS(args=dict(div=div), code=""" const attrs = %s; const args = []; for (let i = 0; i<attrs.length; i++) { args.push(attrs[i] + '=' + Number(cb_obj[attrs[i]]).toFixed(2)); } const line = "<span style=%r><b>" + cb_obj.event_name + "</b>(" + args.join(", ") + ")</span>\\n"; const text = div.text.concat(line); const lines = text.split("\\n") if (lines.length > 35) lines.shift(); div.text = lines.join("\\n"); """ % (attributes, style)) x = [0, 1, 2] y = [0, 1, 2] p = figure() p.line(x, y) hover = HoverTool(tooltips=[ ("(x, y)", "(@x, @y)") ]) hover.point_policy='snap_to_data' p.add_tools(hover) div = Div(width=400, height=p.height, height_policy="fixed") layout = row(p, div) point_attributes = ['x', 'y'] p.js_on_event(events.Tap, display_event(div, attributes=point_attributes)) displayHTML(bembed.file_html(layout, CDN))
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!