Error Bar Chart

Global Temperature Anomalies

Climate data showing global temperature anomalies by decade with measurement uncertainty and trend line.

Output
Global Temperature Anomalies
Python
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(42)

# Climate data - temperature anomalies by decade
decades = ['1960s', '1970s', '1980s', '1990s', '2000s', '2010s', '2020s']
anomaly = np.array([-0.05, 0.02, 0.18, 0.32, 0.52, 0.78, 1.02])
uncertainty = np.array([0.08, 0.07, 0.06, 0.05, 0.04, 0.03, 0.04])

fig, ax = plt.subplots(figsize=(10, 6), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')

# Color based on anomaly value
colors = ['#27D3F5' if a < 0 else '#F54927' for a in anomaly]
alphas = [0.3 + 0.7 * abs(a) for a in anomaly]

for i, (d, a, u, c) in enumerate(zip(decades, anomaly, uncertainty, colors)):
    ax.errorbar(i, a, yerr=u, fmt='o', color=c, ecolor=c,
                elinewidth=2, capsize=6, capthick=2, markersize=12,
                markerfacecolor=c, markeredgecolor='white', markeredgewidth=2)

ax.axhline(y=0, color='#666', linestyle='--', linewidth=1, alpha=0.5)

# Trend line
z = np.polyfit(range(len(decades)), anomaly, 1)
p = np.poly1d(z)
ax.plot(range(len(decades)), p(range(len(decades))), '--', 
        color='#F5B027', linewidth=2, alpha=0.8, label=f'Trend: +{z[0]:.2f}°C/decade')

ax.fill_between(range(len(decades)), anomaly - uncertainty, anomaly + uncertainty,
                color='#F54927', alpha=0.15)

ax.set_xlabel('Decade', fontsize=11, color='white', fontweight='500')
ax.set_ylabel('Temperature Anomaly (°C)', fontsize=11, color='white', fontweight='500')
ax.set_title('Global Temperature Anomalies by Decade', fontsize=14, 
             color='white', fontweight='bold', pad=15)

ax.set_xticks(range(len(decades)))
ax.set_xticklabels(decades)
ax.legend(facecolor='#1a1a2e', edgecolor='#333', labelcolor='white', fontsize=10)
ax.tick_params(colors='#94a3b8', labelsize=9)
ax.grid(True, alpha=0.2, color='#4a4a6a')
for spine in ax.spines.values():
    spine.set_color('#333333')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support