Event Plot

Production Line Defects

Quality control event tracking with severity classification

Output
Production Line Defects
Python
import matplotlib.pyplot as plt
import numpy as np

# Simulate production line events
np.random.seed(42)
lines = ['Line A', 'Line B', 'Line C', 'Line D']
defect_times = [
    np.sort(np.random.exponential(30, 12).cumsum()),
    np.sort(np.random.exponential(45, 8).cumsum()),
    np.sort(np.random.exponential(20, 18).cumsum()),
    np.sort(np.random.exponential(60, 6).cumsum()),
]

# Severity levels (random)
severities = [np.random.choice(['minor', 'major', 'critical'], len(t)) for t in defect_times]

# Create figure
fig, ax = plt.subplots(figsize=(12, 5), facecolor='#F9FAFB')
ax.set_facecolor('#F9FAFB')

color_map = {'minor': '#F59E0B', 'major': '#F97316', 'critical': '#DC2626'}

for i, (times, sevs) in enumerate(zip(defect_times, severities)):
    for sev in ['minor', 'major', 'critical']:
        mask = sevs == sev
        if mask.any():
            lw = 1.5 if sev == 'minor' else 2.5 if sev == 'major' else 4
            ax.eventplot(times[mask], lineoffsets=i, linelengths=0.5, 
                        linewidths=lw, colors=color_map[sev], alpha=0.85)
    
    # Defect rate
    rate = len(times) / 480 * 100
    color = '#10B981' if rate < 3 else '#F59E0B' if rate < 5 else '#EF4444'
    ax.text(490, i, f'{rate:.1f}%', fontsize=10, va='center',
            color=color, fontweight='bold')

# Shift markers
ax.axvline(480, color='#9CA3AF', linewidth=1.5, linestyle='--')
ax.text(240, 3.7, 'Shift Duration: 8 hours', ha='center', fontsize=10, color='#6B7280')

# Legend
for sev, color in color_map.items():
    ax.scatter([], [], c=color, s=50, label=sev.capitalize(), marker='|')
ax.legend(loc='upper right', frameon=True, facecolor='white', fontsize=9)

# Styling
ax.set_yticks(range(len(lines)))
ax.set_yticklabels(lines, fontsize=11, fontweight='600')
ax.set_xlabel('Production Time (minutes)', fontsize=12, fontweight='500', color='#374151')
ax.set_xlim(0, 520)
ax.set_ylim(-0.5, len(lines) - 0.5)

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#D1D5DB')
ax.spines['bottom'].set_color('#D1D5DB')
ax.tick_params(colors='#6B7280', labelsize=10)
ax.xaxis.grid(True, linestyle='--', alpha=0.4, color='#E5E7EB')

# Rate label
ax.text(505, 3.5, 'Defect\nRate', fontsize=8, color='#6B7280', ha='center')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support