我還沒有找到一個簡單的方法來與matplotlib
做到這一點,但如果你不介意瀏覽器顯示,你可以嘗試mpld3。下面是一個例子:
import matplotlib.pyplot as plt
import numpy as np
import mpld3
fig, ax = plt.subplots(subplot_kw=dict(axisbg='#EEEEEE'))
N = 10
# Animals Love x y
# 0 cat 5 0 0
# 1 dog 1 1 0
# 2 elephant 10 0 1
x = np.array([0, 1, 0])
y = np.array([0, 0, 1])
s = np.array([5, 1, 0]) * 1000 # make circle looks bigger
c = np.array(['red', 'green', 'blue'])
labels = ['cat', 'dog', 'elephant']
scatter = ax.scatter(x, y, c=c, s=s, alpha=0.3)
ax.grid(color='white', linestyle='solid')
ax.set_title("Scatter Plot (with tooltips!)", size=20)
tooltip = mpld3.plugins.PointLabelTooltip(scatter, labels=labels)
mpld3.plugins.connect(fig, tooltip)
mpld3.show()
結果(上懸停示出標籤):