如何在matplotlib中绘制带注释的圆圈?
为了在matplotlib中绘制带注释的圆圈,我们需要执行以下步骤-
- 设置图形大小并调整子图之间和周围的填充。
- 使用numpy创建数据点。
- 获取要绘制带注释的圆圈的点坐标。
- 获取当前轴。
- 使用plot()方法绘制数据和数据点。
- 设置X和Y轴刻度。
- 要绘制带圆点的标记,请使用plot()方法,并设置一些属性。
- 注释此圆圈(第7步)以增加箭头样式。
- 要显示图形,请使用 show() 方法。
示例
import matplotlib.pyplot as 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()
输出
它将产生以下输出