File size: 1,514 Bytes
5efaea1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from hrtf_vs_pitch_sonifier import *

normal_color = 'black'
hover_color = 'blue'

# Store original colors to reset them after hover
fig, axes = plt.subplots(2, 2, figsize=(8, 8))

def is_inside_axes(event, ax):
    return ax.get_position().contains(event.x, event.y)

# Event handler for mouse movement
def on_hover(event):
    for ax in axes:
        # Check if the cursor is inside the current subplot
        if is_inside_axes(event, ax):
            # Change color if inside
            for spine in ax.spines.values():
                spine.set_color(hover_color)
        else:
            # Reset to normal color if outside
            for spine in ax.spines.values():
                spine.set_color(normal_color)
    
    fig.canvas.draw_idle()  # Update the figure

def run_test(datasets, idxs, y_mode, show_correct = None):
    fig.canvas.mpl_connect('motion_notify_event', on_hover)

    for i, ax in enumerate(axes.flat):
        ax.scatter(datasets[idxs[i]]["x"], datasets[idxs[i]]["y"] if y_mode == "pitch" else [0] * len(datasets[idxs[i]]["x"]))
        ax.set_title(f"Plot {i + 1}")
        ax.grid(True)

        if show_correct is not None:
            for spine in ax.spines.values():
                if idxs[i] == show_correct:
                        spine.set_linewidth(2)
                        spine.set_color("green")
                else:
                        spine.set_color("red")

    plt.tight_layout()
    plt.show()

y_mode = "static"

run_test(datasets, [0, 2, 3, 5], y_mode)