要在 matplotlib 中放置一个带有注释的圆圈,我们可以采取以下步骤 -
设置图形大小并调整子图之间和周围的填充。
使用 numpy 创建数据点。
获取点坐标以放置带有注释的圆。
获取当前轴。
使用方法绘制数据和数据点plot()。
设置 X 和 Y 轴比例。
要放置一个带圆圈的标记,请使用plot()带有 marker='o' 和一些属性的方法。
用箭头样式注释该圆圈(第 7 步)。
要显示图形,请使用show()方法。
importmatplotlib.pyplotas plt import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True data = np.array([[5, 3, 4, 4, 6], [1, 5, 3, 2, 2]]) point = data[:, 2] ax = plt.gca() ax.plot(data[0], data[1], 'o', ms=10, color='red') ax.set_xlim([2, 8]) ax.set_ylim([0, 6]) radius = 15 ax.plot(point[0], point[1], 'o', ms=radius * 2, mec='yellow', mfc='none', mew=2) ax.annotate('Circled Marker', xy=point, xytext=(60, 60), textcoords='offset points', color='green', size='large', arrowprops=dict( arrowstyle='simple,tail_width=0.3,head_width=0.8,head_length=0.8', facecolor='b', shrinkB=radius * 1.2) ) plt.show()输出结果
它将产生以下输出