Raincloud Plot

Movie Runtime by Genre

Film length distribution across genres

Output
Movie Runtime by Genre
Python
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import ptitprince as pt

np.random.seed(207)
BG_COLOR = '#ffffff'
TEXT_COLOR = '#1f2937'
COLORS = ['#F5276C', '#27D3F5', '#F5B027', '#5314E6']

genres = ['Action', 'Comedy', 'Drama', 'Sci-Fi']
data = pd.DataFrame({
    'Runtime': np.concatenate([
        np.random.normal(125, 20, 90),
        np.random.normal(100, 15, 100),
        np.random.normal(135, 25, 80),
        np.random.normal(140, 22, 70)
    ]),
    'Genre': ['Action']*90 + ['Comedy']*100 + ['Drama']*80 + ['Sci-Fi']*70
})

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

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

ax.set_xlabel('Runtime (minutes)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Genre', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('Movie Runtime by Genre', 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