Home > Net >  How to add hovering annotations with multiple curves
How to add hovering annotations with multiple curves

Time:06-13

I am using matplotlib to plot multiple curves (time series) in one plot. To do this, I use a for loop as seen below.

%matplotlib

for i in range(0, len(force)):

    plt.plot(distance, (force[i]), alpha=0.1)
    
    plt.xlabel('Distance [mm]', fontsize=12)
    plt.ylabel('Force [N]', fontsize=12)

Unfortunately, with the number of curves (approx. 70) that I have, the plot would be unreadable if I labeled each curve. Does anyone know of a way to create labels that only appear when the cursor hovers in the vicinity of that curve (timeseries)?

I looked on the example from this post, but have no clue how to adapt it to my issue:

mplcursors showing 70 labeled curves

If you're working with a Jupyter notebook, you might need %matplotlib nbagg or %matplotlib qt instead of %matplotlib inline to enable interactivity.

  • Related