1

I have a data set in the form of:

data = [('name1','value1','factor1')...[('nameN','valueN','factorN')]

I am trying to plot values as y (x is just the index of that y in data). I want matPlotLib to print the corresponding name and factor of the value on which the mouse pointer hovers. I found one example of that implemented but it used wxPython and unfortunately I can't use that. Any way to do that ( including if name can be shown in the toolbar of matplotlib or just appear as a label on the point and disappear upon moving away of the pointer) would be very helpful.

ARaf
  • 155
  • 1
  • 6
  • What have you tried? You will get better answers here if you have any code (even non-working code). Also see github.com/joferkington/mpldatacursor – tacaswell Sep 24 '13 at 03:51
  • Also see https://stackoverflow.com/questions/7908636/possible-to-make-labels-appear-when-hovering-over-a-point-in-matplotlib – ImportanceOfBeingErnest Jul 07 '18 at 08:26

1 Answers1

0

https://mpld3.github.io/examples/scatter_tooltip.html

import matplotlib.pyplot as plt
import numpy as np
import mpld3

fig, ax = plt.subplots(subplot_kw=dict(axisbg='#EEEEEE'))
N = 100

scatter = ax.scatter(np.random.normal(size=N),
                     np.random.normal(size=N),
                     c=np.random.random(size=N),
                     s=1000 * np.random.random(size=N),
                     alpha=0.3,
                     cmap=plt.cm.jet)
ax.grid(color='white', linestyle='solid')

ax.set_title("Scatter Plot (with tooltips!)", size=20)

labels = ['point {0}'.format(i + 1) for i in range(N)]
tooltip = mpld3.plugins.PointLabelTooltip(scatter, labels=labels)
mpld3.plugins.connect(fig, tooltip)

mpld3.show()

I hope its useful

PhungHV
  • 82
  • 2