การแปลงขนาดจุด Scatter ให้สัมพันธ์กับพิกัดข้อมูล
ขนาดจุดใน scatter plot (parameter s) อยู่ในหน่วย points^2 สามารถปรับให้สัมพันธ์กับข้อมูลได้
ขั้นตอนหลัก
- ตั้งค่าขนาดรูปและ padding
- สร้างจุดข้อมูล X และขนาด s ด้วย numpy
- สร้าง figure และ subplots
- สร้าง scatter plot ด้วย X, s, cmap และสี
- แสดงผลด้วย show()
ตัวอย่างโค้ด
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.array([[1, 1], [2, 1], [2.5, 1]])
s = np.array([20, 10000, 10000])
fig, ax = plt.subplots()
ax.scatter(X[:, 0], X[:, 1], s=s, cmap='plasma', c=s)
plt.show()
คำอธิบาย
ค่า s ควบคุมขนาดจุดในหน่วย points^2 ค่าที่ใหญ่จะทำให้จุดดูใหญ่ขึ้นอย่างมาก