Raincloud Plot

NBA Player Efficiency by Position

Player efficiency ratings across basketball positions

Output
NBA Player Efficiency by Position
Python
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import ptitprince as pt

np.random.seed(104)
BG_COLOR = '#0a0a0f'
TEXT_COLOR = 'white'
COLORS = ['#C82909', '#F5B027', '#6CF527', '#27D3F5', '#5314E6']

positions = ['PG', 'SG', 'SF', 'PF', 'C']
data = pd.DataFrame({
    'PER': np.concatenate([
        np.random.normal(18, 5, 60),
        np.random.normal(16, 4.5, 65),
        np.random.normal(17, 5, 55),
        np.random.normal(19, 5.5, 50),
        np.random.normal(20, 6, 45)
    ]),
    'Position': ['PG']*60 + ['SG']*65 + ['SF']*55 + ['PF']*50 + ['C']*45
})

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

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

ax.set_xlabel('Player Efficiency Rating', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Position', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('NBA Player Efficiency by Position', fontsize=14, color=TEXT_COLOR, fontweight='bold', pad=15)

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

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support