Matplotlib 中有两种标注,一种是无指向性标注 text,另一种是指向性注释 annotate。

无指向性标注 text: plt.text(-0.5, 5, "two functions", family="Times New Roman", fontsize=18, fontweight="bold", color='red') # 在 x 为-0.5,y 为 5 的区域开始文本标注

指向性注释 annotate。 annotate()函数用于注释,xy 参数代表箭头指向的点,xytext 代表文本标注开始的点:

加 circle

1
2
3
4
5
6
7
import matplotlib.pyplot as plt
# draw cicle,(point[0], point[1]) is the center of the circle
plt.plot(x_points[0], y_points[0], 'o',ms=radius * 2, mec='black', mfc='none', mew=2)

# draw arrow pointing the circle
plt.annotate("Attack stop", xy=(x_points[0], y_points[0]), xytext=(
x_points[0]+2, y_points[0]-29), arrowprops=dict(arrowstyle='simple,tail_width=0.2,head_width=0.6,head_length=0.8', facecolor='black', shrinkB=radius * 1.2), fontsize=15)

plt.annotate:

  1. xy(float, float): The point (x, y) to annotate. The coordinate system is determined by xycoords.
  2. xytext(float, float), default: xy: The position (x, y) to place the text at. The coordinate system is determined by textcoords.

参考资料

How do I put a circle with annotation in matplotlib matplotlib.pyplot.annotate — Matplotlib 3.7.2 documentation

图例 Legend,标注(Text,Annotate)【Matplotlib 入门教程 4】 – TuringPlanet