ในการพล็อตวงกลมครึ่งขาวดำครึ่งวงกลมโดยใช้ Matplotlib เราสามารถทำตามขั้นตอนต่อไปนี้ -
- กำหนดขนาดรูปและปรับช่องว่างภายในระหว่างและรอบๆ แผนผังย่อย
- สร้างร่างและชุดแผนย่อย
- เริ่มต้น theta1 และ theta2 เพื่อวาดขอบจาก theta1 ถึง theta2 และในทางกลับกัน
- เพิ่มอินสแตนซ์ลิ่มบนแกนปัจจุบัน
- ตั้งค่าการปรับขนาดเท่ากันโดยเปลี่ยนขีดจำกัดแกน
- ตั้งค่า x และ ย มาตราส่วน
- หากต้องการแสดงรูป ให้ใช้ show() วิธีการ
ตัวอย่าง
import matplotlib.pyplot as plt
from matplotlib.patches import Wedge
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
fig, ax = plt.subplots()
theta1, theta2 = 0, 0 + 180
radius = 2
center = (0, 0)
w1 = Wedge(center, radius, theta1, theta2, fc='black', edgecolor='black')
w2 = Wedge(center, radius, theta2, theta1, fc='white', edgecolor='black')
for wedge in [w1, w2]:
ax.add_artist(wedge)
ax.axis('equal')
ax.set_xlim(-5, 5)
ax.set_ylim(-5, 5)
plt.show() ผลลัพธ์
