ในการใส่วงกลมพร้อมคำอธิบายประกอบใน matplotlib เราสามารถทำตามขั้นตอนต่อไปนี้ -
- กำหนดขนาดรูปและปรับช่องว่างภายในระหว่างและรอบๆ แผนผังย่อย
- สร้างจุดข้อมูลโดยใช้ numpy
- รับพิกัดจุดเพื่อใส่วงกลมพร้อมคำอธิบายประกอบ
- รับแกนปัจจุบัน
- พล็อตข้อมูลและจุดข้อมูลโดยใช้เมธอด plot()
- ตั้งค่ามาตราส่วนแกน X และ Y
- หากต้องการใส่เครื่องหมายวงกลม ให้ใช้เมธอด plot() พร้อม marker='o' และคุณสมบัติบางอย่าง
- ใส่คำอธิบายประกอบให้กับวงกลมนั้น (ขั้นตอนที่ 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() ผลลัพธ์
มันจะสร้างผลลัพธ์ต่อไปนี้
