ตัวอย่างนี้ใช้แกน x เป็นยอดขาย แกน y เป็นมาร์จิน และขนาดฟองแทนจำนวนลูกค้า เพื่อแสดง 3 ตัวแปรพร้อมกันในกราฟเดียว
import numpy as np
import matplotlib.pyplot as plt
segments = ["Enterprise", "SMB", "Startup", "Consumer", "Partner"]
revenue = np.array([320, 180, 90, 70, 150])
margin = np.array([28, 22, 15, 12, 20])
customers = np.array([45, 110, 260, 520, 160])
fig, ax = plt.subplots(figsize=(6, 4))
scatter = ax.scatter(
revenue,
margin,
s=customers,
c=margin,
cmap="Blues",
alpha=0.7,
edgecolors="#1f2937",
)
for x, y, label in zip(revenue, margin, segments):
ax.text(x, y, label, fontsize=10, ha="center", va="center")
ax.set_xlabel("ยอดขาย (ล้านเยน)")
ax.set_ylabel("อัตรากำไร (%)")
ax.set_title("ยอดขาย มาร์จิน และจำนวนลูกค้าแยกตามกลุ่ม")
ax.grid(alpha=0.3)
cbar = fig.colorbar(scatter, ax=ax)
cbar.set_label("อัตรากำไร (%)")
fig.tight_layout()
plt.show()

เทคนิคการอ่าน #
- ปรับขนาดฟองให้แปรผันตามพื้นที่ (ไม่ใช่รัศมี) เพื่อให้การเปรียบเทียบไม่ผิดเพี้ยน
- ถ้าฟองทับกันมาก ให้ขยับตำแหน่งหรือเพิ่มความโปร่งใส
- การเขียนชื่อกลุ่มไว้กลางฟองช่วยลดความจำเป็นต้องมีคำอธิบายแยกต่างหาก