Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting mouse coordinates from click on heatmap #1260

Open
JohnMrziglod opened this issue Jan 19, 2021 · 1 comment
Open

Getting mouse coordinates from click on heatmap #1260

JohnMrziglod opened this issue Jan 19, 2021 · 1 comment

Comments

@JohnMrziglod
Copy link

Hi,

I try to get the clicked coordinate on a HeatMap. Unfortunately, neither does on_click, on_element_click or on_background_click seem to work (see example below).

import numpy as np
from bqplot import (Figure, LinearScale, ColorScale, 
                    Color, Axis, HeatMap, ColorAxis)
from ipywidgets import Label, Layout

def print_event(*args, **kwargs):
    print("test!")

x = np.linspace(-5, 5, 200)
y = np.linspace(-5, 5, 200)
X, Y = np.meshgrid(x, y)
color = np.cos(X**2 + Y**2)

x_sc, y_sc, col_sc = LinearScale(), LinearScale(), ColorScale(scheme='RdYlBu')
heat = HeatMap(x=x, y=y, color=color,
               scales={'x': x_sc, 'y': y_sc, 'color': col_sc})

# It doesn't matter which event to catch, none of them fires print_event
heat.on_hover(print_event)
heat.on_element_click(print_event)
heat.on_click(print_event)
heat.on_background_click(print_event)

ax_x = Axis(scale=x_sc)
ax_y = Axis(scale=y_sc, orientation='vertical')
ax_c = ColorAxis(scale=col_sc)
fig = Figure(marks=[heat], axes=[ax_x, ax_y, ax_c],
             title='Cosine',
             layout=Layout(width='650px', height='650px'),
             min_aspect_ratio=1, max_aspect_ratio=1, padding_y=0)

Do I miss something? Or is there another way to get the mouse position when a user clicks on a point in my heatmap?
I tried the solution from #973 but without success, no events were triggered.

@gerazov
Copy link

gerazov commented Mar 5, 2023

Also stuck ...

Found this for GridHeatMap but it doesn't work, i.e. the callback is not triggered ...
https://uiuc-ischool-dataviz.github.io/is445_spring2021/nbv.html?notebook_name=%2Fis445_spring2021%2Fweek05%2Fprep_notebook_week05.ipynb

# 4. Marks -- lets now re-do our heat map & add in some interactivity:
heat_map = bqplot.GridHeatMap(color = data,
                              scales = {'color': col_sc,
                                        'row': y_sc,
                                        'column': x_sc},
                              interactions = {'click': 'select'}, # make interactive on click of each box
                              anchor_style = {'fill':'blue'}, # to make our selection blue
                              selected_style = {'opacity': 1.0}, # make 100% opaque if box is selected
                              unselected_style = {'opacity': 0.8}) # make a little see-through if not

heat_map.observe(on_selected, 'selected')
def on_selected(change):
    print(change['owner'].selected)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants