การแสดงสาเหตุหลักหรือหมวดหมู่คำถามแบบสะสม พาเรโตชาร์ตเป็นวิธีมาตรฐาน ผสมกราฟแท่งกับเส้นสะสมเพื่อชี้จุด 80/20 ให้ชัด
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter
categories = ["ตั้งค่าผิด", "ใช้งานไม่ถูก", "บั๊ก", "คำถามสเปก", "เออเรอร์เชื่อมต่อ", "อื่นๆ"]
counts = np.array([120, 95, 70, 45, 30, 18])
sorted_idx = np.argsort(counts)[::-1]
counts = counts[sorted_idx]
categories = [categories[i] for i in sorted_idx]
cumulative = counts.cumsum() / counts.sum()
fig, ax1 = plt.subplots(figsize=(6.4, 4))
ax1.bar(categories, counts, color="#38bdf8")
ax1.set_ylabel("จำนวน")
ax1.set_title("พาเรโตของหมวดหมู่คำถาม")
ax1.grid(axis="y", alpha=0.2)
ax2 = ax1.twinx()
ax2.plot(categories, cumulative, color="#ef4444", marker="o")
ax2.set_ylabel("สัดส่วนสะสม")
ax2.set_ylim(0, 1.05)
ax2.yaxis.set_major_formatter(FuncFormatter(lambda x, _: f"{x:.0%}"))
threshold = np.argmax(cumulative >= 0.8)
ax2.axhline(0.8, color="#475569", linestyle="--", linewidth=1)
ax1.axvline(threshold + 0.5, color="#475569", linestyle=":", linewidth=1)
fig.tight_layout()
plt.show()

อ่านอย่างไร #
- แท่งคือจำนวนรายหมวด เส้นคือสัดส่วนสะสม
- เส้น 80% ชี้หมวดที่ควรเร่งแก้เป็นพิเศษ
- ถ้าเส้นไต่ขึ้นช้า แปลว่าสาเหตุกระจาย ต้องปรับปรุงเชิงกว้าง