Matplotlib库 标注在工作有很大作用: Annotate的构造函数为 :Annotation(s, xy, xytext=None, xycoords=‘data’, textcoords=None, arrowprops=None, annotation_clip=None, **kwargs) 关键参数:
arrowprops为箭头的样式,dict(字典)型数据,如果该属性非空,则会在注释文本和被注释点之间画一个箭头。如果不设置’arrowstyle’关键字,则允许包含关键字width、headwidth、headlength、shrink,以下是arrowstyle的可选值
案例 import numpy as np import matplotlib.pylab as plt x = np.arange(0, 10, 0.005) y = np.exp(-x / 2.) * np.sin(2 * np.pi * x) fig = plt.figure() ax = fig.add_subplot(111) ax.plot(x, y) ax.set_xlim(0, 10) ax.set_ylim(-1, 1) xdata, ydata = 5, 0 xdisplay, ydisplay = ax.transData.transform_point((xdata, ydata)) bbox = dict(boxstyle="round", fc="0.8") arrowprops = dict(arrowstyle="<|-|>",connectionstyle="angle,angleA=0,angleB=90,rad=10") offset = 100 ax.annotate('data = (%.1f, %.1f)' % (xdata, ydata), xy=(xdata, ydata), xytext=(1 * offset, offset), textcoords='offset pixels', bbox=bbox, arrowprops=arrowprops) disp = ax.annotate('display = (%.1f, %.1f)' % (xdisplay, ydisplay), (xdisplay, ydisplay), xytext=(0.5 * offset, -offset), xycoords='figure pixels', textcoords='offset points', bbox=bbox, arrowprops=arrowprops) plt.show() 来源:https://www./content-4-701051.html |
|