Bar Chart

GDP Ranking Bar

Sorted ranking with gradient palette.

Output
GDP Ranking Bar
Python
import matplotlib.pyplot as plt
import numpy as np

COLORS = {
    'gradient': ['#6366F1', '#818CF8', '#A5B4FC', '#C7D2FE', '#E0E7FF'],
    'background': '#FFFFFF',
    'text': '#1E293B',
    'text_muted': '#64748B',
}

countries = ['USA', 'China', 'Japan', 'Germany', 'UK']
values = [21.4, 17.7, 4.9, 4.2, 3.1]

fig, ax = plt.subplots(figsize=(10, 5), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])

y = np.arange(len(countries))

for i, (v, c) in enumerate(zip(values, COLORS['gradient'])):
    ax.barh(i, v, height=0.55, color=c, alpha=0.85, edgecolor='white', linewidth=2, zorder=3)
    ax.text(v + 0.3, i, f'${v}T', ha='left', va='center', fontsize=10,
            fontweight='bold', color=COLORS['text'])
    ax.text(-0.3, i, countries[i], ha='right', va='center', fontsize=10,
            fontweight='bold', color=COLORS['text'])

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['bottom'].set_visible(False)

ax.tick_params(left=False, labelleft=False, bottom=False, labelbottom=False)
ax.set_xlim(-3, 25)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Basic Charts

Did this help you?

Support PyLucid to keep it free & growing

Support