Raincloud Plot

Renewable Energy Capacity Factor Raincloud

Comparing capacity factors across renewable energy technologies.

Output
Renewable Energy Capacity Factor Raincloud
Python
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as stats

np.random.seed(999)

# Capacity factor percentage
solar = np.random.normal(25, 6, 100)
onshore_wind = np.random.normal(35, 8, 95)
offshore_wind = np.random.normal(45, 7, 70)
hydro = np.random.normal(42, 10, 80)

solar = np.clip(solar, 10, 45)
onshore_wind = np.clip(onshore_wind, 15, 55)
offshore_wind = np.clip(offshore_wind, 28, 65)
hydro = np.clip(hydro, 20, 70)

F_stat, p_value = stats.f_oneway(solar, onshore_wind, offshore_wind, hydro)

BG_COLOR = "#0d1117"
COLOR_SCALE = ["#F5D327", "#6CF527", "#27D3F5", "#276CF5"]

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

y_data = [solar, onshore_wind, offshore_wind, hydro]
positions = [0, 1, 2, 3]
labels = ["Solar PV", "Onshore Wind", "Offshore Wind", "Hydropower"]

for h in [20, 40, 60]:
    ax.axhline(h, color='#333333', ls=(0, (5, 5)), alpha=0.5, zorder=0)

# Grid parity threshold
ax.axhline(y=30, color='#22c55e', ls='--', alpha=0.7, lw=2)
ax.text(3.55, 30, "Grid Parity", color='#22c55e', fontsize=9, va='center')

violins = ax.violinplot(y_data, positions=positions, widths=0.5, 
                         bw_method="silverman", showmeans=False, 
                         showmedians=False, showextrema=False)
for pc in violins["bodies"]:
    pc.set_facecolor("none")
    pc.set_edgecolor("#F5B027")
    pc.set_linewidth(2)

bp = ax.boxplot(y_data, positions=positions, showfliers=False, showcaps=False,
                medianprops=dict(linewidth=3, color='white'),
                whiskerprops=dict(linewidth=2, color='#555555'),
                boxprops=dict(linewidth=2, color='#555555'))

for i, (y, color) in enumerate(zip(y_data, COLOR_SCALE)):
    x_jitter = np.array([i] * len(y)) + stats.t(df=6, scale=0.04).rvs(len(y))
    ax.scatter(x_jitter, y, s=55, color=color, alpha=0.55, zorder=2)

means = [y.mean() for y in y_data]
for i, (mean, color) in enumerate(zip(means, COLOR_SCALE)):
    ax.scatter(i, mean, s=180, color='#C82909', zorder=5, edgecolors='white', linewidths=2)
    ax.plot([i, i + 0.28], [mean, mean], ls="dashdot", color="white", zorder=3, lw=1.5)
    ax.text(i + 0.3, mean, f"μ={mean:.1f}%", fontsize=10, va="center", color='white',
            bbox=dict(facecolor=BG_COLOR, edgecolor=color, boxstyle="round,pad=0.15", lw=2))

# LCOE annotations
lcoe = ["$30/MWh", "$35/MWh", "$55/MWh", "$40/MWh"]
for i, (cost, color) in enumerate(zip(lcoe, COLOR_SCALE)):
    ax.text(i, 5, f"LCOE: {cost}", ha='center', fontsize=9, color=color)

ax.spines["right"].set_visible(False)
ax.spines["top"].set_visible(False)
ax.spines["left"].set_color('#444444')
ax.spines["bottom"].set_color('#444444')
ax.tick_params(colors='#888888', length=0)

xlabels = [f"{l}\n(n={len(y_data[i])})" for i, l in enumerate(labels)]
ax.set_xticks(positions)
ax.set_xticklabels(xlabels, size=11, color='white')
ax.set_ylabel("Capacity Factor (%)", size=14, color='white', fontweight='bold')

ax.set_title("Renewable Energy Capacity Factors", fontsize=14, color="white", fontweight="bold", pad=20)


ax.set_ylim(0, 75)
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support