Matplotlib รองรับ marker แบบ tuple: (num_sides, style, rotation) เช่น (3, 0, angle) สำหรับสามเหลี่ยมหมุนตามมุมที่กำหนด ใช้ได้กับ plt.plot() และ plt.scatter()
ขั้นตอนการทำงาน
- ตั้งค่าขนาดรูปและเลย์เอาต์
- สร้างข้อมูล x, y แบบสุ่ม
- สร้างอาร์เรย์มุมหมุนต่างกัน
- วนลูป zip(x, y, angles) พลอตแต่ละจุดด้วย marker tuple
- แสดงผล
ตัวอย่างโค้ด
import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.random.rand(10)
y = np.random.rand(10)
angles = np.linspace(0, 10, 10)
for x, y, i in zip(x, y, angles):
plt.plot(x, y, marker=(3, 0, i*45), linestyle='None', markersize=20)
plt.show()
ผลลัพธ์
