ANOVA Boxplot
Solar Panel Efficiency ANOVA
Comparing energy conversion efficiency across solar cell technologies.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as stats
np.random.seed(654)
# Efficiency percentage
monocrystalline = np.random.normal(21.5, 1.5, 100)
polycrystalline = np.random.normal(17.8, 1.8, 100)
thin_film = np.random.normal(12.5, 2.2, 100)
perovskite = np.random.normal(24.2, 2.5, 100)
F_stat, p_value = stats.f_oneway(monocrystalline, polycrystalline, thin_film, perovskite)
fig, ax = plt.subplots(figsize=(12, 7), facecolor='#0d1117')
ax.set_facecolor('#0d1117')
colors = ['#276CF5', '#27D3F5', '#F5B027', '#6CF527']
data = [monocrystalline, polycrystalline, thin_film, perovskite]
bp = ax.boxplot(data, positions=[1, 2, 3, 4], widths=0.6, patch_artist=True,
medianprops={'color': 'white', 'linewidth': 2},
whiskerprops={'color': '#555555', 'linewidth': 1.5},
capprops={'color': '#555555', 'linewidth': 1.5},
flierprops={'marker': 'o', 'markerfacecolor': '#444444', 'markersize': 4})
for patch, color in zip(bp['boxes'], colors):
patch.set_facecolor(color)
patch.set_alpha(0.7)
patch.set_edgecolor('white')
patch.set_linewidth(1.5)
labels = ['Monocrystalline', 'Polycrystalline', 'Thin Film', 'Perovskite']
# Cost per watt
costs = ['$0.30/W', '$0.25/W', '$0.18/W', '$0.40/W']
for i, (d, cost, color) in enumerate(zip(data, costs, colors)):
ax.text(i+1, 6, f'μ={d.mean():.1f}% | {cost}', ha='center', fontsize=8, color=color)
# Threshold lines
ax.axhline(y=20, color='#22c55e', linestyle='--', alpha=0.6, linewidth=1.5)
ax.text(4.45, 20, 'Premium', fontsize=8, color='#22c55e', va='center')
# Stats header
stats_text = f"ANOVA: F={F_stat:.1f}, p<0.001 | Highest Efficiency: Perovskite (μ={perovskite.mean():.1f}%)"
bbox = dict(boxstyle="round,pad=0.3", facecolor='#1a1a2e', edgecolor='#6CF527', lw=2)
ax.text(0.5, 1.02, stats_text, transform=ax.transAxes, fontsize=9, color='white',
ha='center', va='bottom', fontfamily='monospace', bbox=bbox)
ax.set_xticks([1, 2, 3, 4])
ax.set_xticklabels(labels, fontsize=10, color='white')
ax.set_ylabel('Conversion Efficiency (%)', fontsize=12, color='white', fontweight='500')
ax.set_title('Solar Cell Technology Comparison\nLaboratory Efficiency Measurements',
fontsize=14, color='white', fontweight='bold', pad=25)
ax.tick_params(colors='#888888')
for spine in ax.spines.values():
spine.set_color('#333333')
ax.yaxis.grid(True, color='#1a1a2e', linewidth=0.5)
ax.set_axisbelow(True)
ax.set_ylim(4, 32)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
More ANOVA Boxplot examples
☕