答案 0 :(得分:2)
在matplotlib doc Annotations中,您可以使用代码修改示例
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
t = np.arange(0.0, 5.0, 0.01)
s = np.cos(2*np.pi*t)
line, = ax.plot(t, s, lw=2)
ax.plot(2, 1, marker = "v", color='blue', fillstyle='none')
bbox_props = dict(boxstyle="square,pad=0.3", fc="white", ec="black", lw=1.2)
t = ax.annotate('local max\n x = 2, y = 1', xy=(2, 1), xytext=(3, 1.5),
arrowprops=dict(arrowstyle="-", facecolor='black'), bbox=bbox_props,
)
ax.set_ylim(-2, 2)
plt.show()
答案 1 :(得分:0)
您可以使用Bokeh框架替代matplotlib。 (我个人觉得更好)。
for plot in [p1, p3, p5]:
plot.add_tools(HoverTool(
tooltips=[
("(x,y, name)", "($x, $y, $name"), # use @{ } for field names with spaces
],
formatters={
'date': 'datetime', # use 'datetime' formatter for 'date' field
'adj close': 'printf', # use 'printf' formatter for 'adj close' field
# use default 'numeral' formatter for other fields
},
# display a tooltip whenever the cursor is vertically in line with a glyph
# mode='hline'
mode='mouse'
))