給圖像添加註釋
import numpy as np
import matplotlib.pyplot as plt
# 生成X數據
x_data = np.linspace(-2,2,50)
# Y數據
y1 = np.sin(10*x_data)*np.exp(-x_data) - 0.5
y2 = np.square(x_data)
l1, = plt.plot(x_data, y1, c='r', lw=2, ls = '-.')
l2, = plt.plot(x_data, y2, c='g')
plt.xlabel('X')
plt.ylabel('Y')
plt.legend(handles=[l1, l2], labels=['$sin(x)*exp(x)$', '$x^2$'])
###########################
plt.scatter([-1.64], [2.7], c='b', marker='^',s=35)
plt.annotate('This is point(%.3f, %.3f)'%(-1.64, 2.7), # 註釋內容
xy=(-1.64, 2.7), # 註釋點
xytext=(x_data[5]+1,y1[5]+2), # 文本位置
xycoords='data', # 註釋點座標系統
arrowprops={'arrowstyle':'->', 'connectionstyle':"arc3,rad=.2"}) #指示線類型
##########################
plt.savefig('d:/f.png')
plt.show()