在使用Matplotlib画图过程中,有些内容必须鼠标点击或者划过才可以显示,这个问题可以依赖于annotate(s='str' ,xy=(x,y) ,xytext=(l1,l2) ,..)这个函数,其中s 为注释文本内容 , xy 为被注释的坐标点, xytext 为注释文字的坐标位置,其他参数可自行百度哈。当鼠标滑过时候,将其设置为可见,默认情况下为隐藏。下面是一个小例子:
# -*- coding: UTF-8 -*-
import matplotlib.pyplot as plt
fig = plt.figure()
po_annotation = []
for i in range(0, 10):
x = i
y = x**2
point, = plt.plot(x, y, 'o')
annotation = plt.annotate(('x='+str(x), 'y='+str(y)), xy=(x+0.1, y+0.1), xycoords='data', xytext=(x+0.7, y+0.7),
textcoords='data', horizontalalignment="left",
arrowprops=dict(arrowstyle="simple",connectionstyle="arc3,rad=-0.1"),
bbox=dict(boxstyle="roun