1 Annoate
关于annotate更多的参数解释可以查看官方文档的注释内容,写的很全面,这里给出几个常用的参数用法,能够更好的掌握annotate
的用法。
主要的参数:
text : str
The text of the annotation. s is a deprecated synonym for this parameter.
xy : (float, float)
The point (x,y) to annotate.
xytext : (float, float), optional
The position (x,y) to place the text at. If None, defaults to xy.
import numpy as np
import matplotlib.pyplot as plt
font = {'family': 'serif',
'color': 'darkred',
'weight': 'normal',
'size': 16,
}
x = np.linspace(0.0, 5.0, 10000)
y = np.cos(2 * np.pi * x) * np.exp(-x)
plt.plot(x, y, 'k')
plt.title('Damped exponential decay', fontdict=font)
plt.text(2, 0.65, r'$\cos(2 \pi t) \exp(-t)$', fontdict=font)
plt.xlabel('time (s)', fontdict=font)
plt.ylabel('voltage (mV)', fontdict=font)
# Tweak spacing to prevent clipping of ylabel
plt.subplots_adjust(left=0.15)
plt.annotate(s="matplotlib annotate", xy=(0.46, -0.617), xytext=(0.8, -0.5), arrowprops={"arrowstyle": "->"}, fontsize=16)
plt.show()
最终结果如下: