ในการใช้ pyplot.arrow หรือ patches.Arrow() ใน matplotlib เราสามารถทำตามขั้นตอนต่อไปนี้:
- ตั้งค่าขนาดรูปและปรับ padding ระหว่างและรอบ subplots
- เริ่มต้นตัวแปร 4 ตัว x_tail, y_tail, x_head และ y_head
- สร้าง figure และชุด subplots
- รับอินสแตนซ์ fancy arrow
- เพิ่ม artist (ขั้นตอน 4) ด้วยเมธอด add_patch()
- เพื่อแสดงรูป ใช้เมธอด show()
ตัวอย่าง
from matplotlib import pyplot as plt, patches as mpatches plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x_tail = 0.1 y_tail = 0.1 x_head = 0.9 y_head = 0.9 fig, ax = plt.subplots() arrow = mpatches.FancyArrowPatch((x_tail, y_tail), (x_head, y_head), mutation_scale=100, color='green') ax.add_patch(arrow) plt.show()
ผลลัพธ์

