ใส่ข้อความตรงกลางวงกลม
ใช้ Circle patch และ text() วางข้อความ
ขั้นตอน
- สร้าง figure ด้วย figure()
- เพิ่ม subplot
- สร้าง Circle instance ด้วย Circle()
- เพิ่ม circle patch ลง plot
- ใช้ text() วางข้อความในวงกลม
- ปรับขนาดแกน x, y ด้วย xlim() และ ylim()
- แสดงด้วย show()
ตัวอย่างโค้ด
import matplotlib
from matplotlib import pyplot as plt, patches
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
fig = plt.figure()
ax = fig.add_subplot(111)
circle = matplotlib.patches.Circle((0, 0), radius=1, color='yellow')
ax.add_patch(circle)
plt.text(-.25, 0, "This is a Circle")
plt.xlim([-4, 4])
plt.ylim([-4, 4])
plt.axis('equal')
plt.show()
ผลลัพธ์
