Raincloud Plot

Commute Time by Transportation Mode

Travel duration across commute methods

Output
Commute Time by Transportation Mode
Python
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import ptitprince as pt

np.random.seed(217)
BG_COLOR = '#ffffff'
TEXT_COLOR = '#1f2937'
COLORS = ['#27D3F5', '#6CF527', '#F54927', '#5314E6']

modes = ['Bike', 'Transit', 'Car', 'Walk']
data = pd.DataFrame({
    'Time': np.concatenate([
        np.random.normal(22, 6, 70),
        np.random.normal(35, 12, 100),
        np.random.normal(30, 15, 120),
        np.random.normal(18, 5, 50)
    ]),
    'Mode': ['Bike']*70 + ['Transit']*100 + ['Car']*120 + ['Walk']*50
})

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

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

ax.set_xlabel('Commute Time (minutes)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Transportation Mode', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('Commute Time by Mode', 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