Area Chart
Statistical Power Curve
Power as function of sample size - R style
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
effect_sizes = [0.2, 0.5, 0.8] # Cohen's d
n_range = np.arange(10, 201, 5)
alpha = 0.05
fig, ax = plt.subplots(figsize=(10, 6), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')
colors = ['#27D3F5', '#6CF527', '#F5276C']
labels = ['Small (d=0.2)', 'Medium (d=0.5)', 'Large (d=0.8)']
for d, color, label in zip(effect_sizes, colors, labels):
power = []
for n in n_range:
# Power for two-sample t-test
nc = d * np.sqrt(n/2) # Non-centrality parameter
crit = stats.t.ppf(1 - alpha/2, 2*n - 2)
pow_val = 1 - stats.nct.cdf(crit, 2*n - 2, nc) + stats.nct.cdf(-crit, 2*n - 2, nc)
power.append(pow_val)
ax.fill_between(n_range, 0, power, alpha=0.2, color=color)
ax.plot(n_range, power, color=color, linewidth=2.5, label=label)
ax.axhline(0.8, color='#F5B027', linewidth=2, linestyle='--', label='Target (80%)')
ax.axhline(0.9, color='#F5B027', linewidth=1, linestyle=':', alpha=0.7)
ax.set_xlabel('Sample Size (per group)', color='white', fontsize=11, fontweight='500')
ax.set_ylabel('Statistical Power', color='white', fontsize=11, fontweight='500')
ax.set_title('Power Analysis: Two-Sample t-test (α=0.05)', 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.yaxis.grid(True, color='#1a1a2e', linewidth=0.5)
ax.set_xlim(10, 200)
ax.set_ylim(0, 1)
ax.legend(facecolor='#0a0a0f', edgecolor='#333333', labelcolor='white', loc='lower right')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Basic Charts
More Area Chart examples
☕