Area Chart
Bootstrap Distribution
Bootstrap resampling distribution with percentile CI - R style
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
np.random.seed(42)
original_data = np.random.exponential(5, 50)
original_mean = np.mean(original_data)
# Bootstrap
n_boot = 5000
boot_means = [np.mean(np.random.choice(original_data, size=len(original_data), replace=True))
for _ in range(n_boot)]
x = np.linspace(min(boot_means), max(boot_means), 100)
kde = stats.gaussian_kde(boot_means)
density = kde(x)
ci_low, ci_high = np.percentile(boot_means, [2.5, 97.5])
fig, ax = plt.subplots(figsize=(10, 6), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')
ax.fill_between(x, 0, density, alpha=0.5, color='#F5B027')
ax.plot(x, density, color='#F5B027', linewidth=2)
# CI shading
ci_mask = (x >= ci_low) & (x <= ci_high)
ax.fill_between(x, 0, density, where=ci_mask, alpha=0.3, color='#6CF527')
ax.axvline(original_mean, color='#F5276C', linewidth=2.5, linestyle='-', label=f'Sample mean: {original_mean:.2f}')
ax.axvline(ci_low, color='#27D3F5', linewidth=1.5, linestyle='--', label=f'95% CI: [{ci_low:.2f}, {ci_high:.2f}]')
ax.axvline(ci_high, color='#27D3F5', linewidth=1.5, linestyle='--')
ax.set_xlabel('Bootstrap Mean', color='white', fontsize=11, fontweight='500')
ax.set_ylabel('Density', color='white', fontsize=11, fontweight='500')
ax.set_title(f'Bootstrap Distribution (B={n_boot})', color='white', fontsize=13, fontweight='600', pad=15)
ax.tick_params(colors='#888888', labelsize=9)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#333333')
ax.spines['bottom'].set_color('#333333')
ax.legend(facecolor='#0a0a0f', edgecolor='#333333', labelcolor='white')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Basic Charts
More Area Chart examples
☕