Error Bar Chart
Economic Growth Indicators
GDP growth and inflation rates comparison across major economies with forecast uncertainty ranges.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(42)
# Economic data
countries = ['USA', 'China', 'Germany', 'Japan', 'UK', 'India', 'Brazil']
gdp_growth = np.array([2.5, 5.2, 1.8, 1.2, 1.5, 6.8, 2.8])
inflation = np.array([3.2, 2.1, 2.8, 2.5, 4.1, 5.5, 4.8])
gdp_ci = np.array([0.4, 0.6, 0.3, 0.2, 0.3, 0.8, 0.5])
inf_ci = np.array([0.3, 0.2, 0.3, 0.2, 0.4, 0.5, 0.4])
fig, ax = plt.subplots(figsize=(10, 6), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')
x = np.arange(len(countries))
# GDP growth (positive indicator)
ax.errorbar(x - 0.15, gdp_growth, yerr=gdp_ci, fmt='o', color='#6CF527',
ecolor='#6CF527', elinewidth=2, capsize=5, markersize=12,
markeredgecolor='white', markeredgewidth=1.5,
label='GDP Growth (%)', alpha=0.9)
# Inflation (can be concerning if high)
colors_inf = ['#F5B027' if i < 3.5 else '#F5276C' for i in inflation]
for i, (inf, ci, c) in enumerate(zip(inflation, inf_ci, colors_inf)):
ax.errorbar(x[i] + 0.15, inf, yerr=ci, fmt='s', color=c,
ecolor=c, elinewidth=2, capsize=5, markersize=10,
markeredgecolor='white', markeredgewidth=1.5, alpha=0.9)
# Custom legend
from matplotlib.lines import Line2D
legend_elements = [
Line2D([0], [0], marker='o', color='w', markerfacecolor='#6CF527',
markersize=10, label='GDP Growth (%)'),
Line2D([0], [0], marker='s', color='w', markerfacecolor='#F5B027',
markersize=10, label='Inflation (%) - Moderate'),
Line2D([0], [0], marker='s', color='w', markerfacecolor='#F5276C',
markersize=10, label='Inflation (%) - High')
]
ax.axhline(y=3.5, color='#F5276C', linestyle='--', linewidth=1, alpha=0.5)
ax.text(6.5, 3.7, 'Inflation target', color='#F5276C', fontsize=9, alpha=0.7)
ax.set_xlabel('Country', fontsize=11, color='white', fontweight='500')
ax.set_ylabel('Rate (%)', fontsize=11, color='white', fontweight='500')
ax.set_title('Economic Indicators by Country (2024)', fontsize=14,
color='white', fontweight='bold', pad=15)
ax.set_xticks(x)
ax.set_xticklabels(countries)
ax.legend(handles=legend_elements, facecolor='#1a1a2e', edgecolor='#333',
labelcolor='white', fontsize=9, loc='upper left')
ax.tick_params(colors='#94a3b8', labelsize=9)
ax.set_ylim(0, 9)
ax.grid(True, axis='y', alpha=0.2, color='#4a4a6a')
for spine in ax.spines.values():
spine.set_color('#333333')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
More Error Bar Chart examples
☕