Raincloud Plot

Call Duration by Department

Customer service call lengths

Output
Call Duration by Department
Python
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import ptitprince as pt

np.random.seed(215)
BG_COLOR = '#ffffff'
TEXT_COLOR = '#1f2937'
COLORS = ['#4927F5', '#F54927', '#27F5B0', '#F5D327']

depts = ['Sales', 'Support', 'Billing', 'Returns']
data = pd.DataFrame({
    'Duration': np.concatenate([
        np.random.gamma(3, 3, 100),
        np.random.gamma(5, 4, 120),
        np.random.gamma(2, 2, 90),
        np.random.gamma(4, 3.5, 85)
    ]),
    'Dept': ['Sales']*100 + ['Support']*120 + ['Billing']*90 + ['Returns']*85
})

fig, ax = plt.subplots(figsize=(10, 6), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)

pt.RainCloud(x='Dept', y='Duration', data=data, palette=COLORS,
             bw=.2, width_viol=.6, ax=ax, orient='h', alpha=.65,
             dodge=True, pointplot=False, move=.2)

ax.axvline(10, color='#22c55e', linestyle='--', alpha=0.6, linewidth=1.5)
ax.text(10.5, 3.5, 'Target', color='#22c55e', fontsize=9)

ax.set_xlabel('Call Duration (minutes)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Department', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('Call Duration by Department', fontsize=14, color=TEXT_COLOR, fontweight='bold', pad=15)

ax.tick_params(colors='#374151', labelsize=10)
for spine in ax.spines.values():
    spine.set_color('#e5e7eb')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support