Raincloud Plot

Stock Returns by Market Sector

Annual returns distribution across sectors

Output
Stock Returns by Market Sector
Python
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import ptitprince as pt

np.random.seed(110)
BG_COLOR = '#0a0a0f'
TEXT_COLOR = 'white'
COLORS = ['#22c55e', '#F54927', '#27D3F5', '#F5B027']

sectors = ['Tech', 'Energy', 'Healthcare', 'Finance']
data = pd.DataFrame({
    'Returns': np.concatenate([
        np.random.normal(18, 25, 90),
        np.random.normal(8, 30, 85),
        np.random.normal(12, 18, 95),
        np.random.normal(10, 20, 88)
    ]),
    'Sector': ['Tech']*90 + ['Energy']*85 + ['Healthcare']*95 + ['Finance']*88
})

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

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

ax.axvline(0, color='#ef4444', linestyle='--', alpha=0.5, linewidth=1)
ax.set_xlabel('Annual Return (%)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Sector', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('Stock Returns by Market Sector', 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