Dendrogram

Country Economic Clusters Light

Economic indicator clustering of countries

Output
Country Economic Clusters Light
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy.cluster.hierarchy import dendrogram, linkage, set_link_color_palette

np.random.seed(147)

countries = ['USA', 'China', 'Japan', 'Germany', 'UK', 'France', 'India',
             'Brazil', 'Canada', 'Australia', 'S. Korea', 'Mexico']

economic_data = np.random.rand(len(countries), 8) * 100
Z = linkage(economic_data, method='complete')

fig, ax = plt.subplots(figsize=(13, 7), facecolor='#ffffff')
ax.set_facecolor('#ffffff')

set_link_color_palette(['#27D3F5', '#F5276C', '#6CF527', '#F5D327', '#5314E6'])

dn = dendrogram(Z, labels=countries, leaf_rotation=35, leaf_font_size=11,
                color_threshold=0.55*max(Z[:,2]), above_threshold_color='#9ca3af', ax=ax)

ax.set_title('Global Economic Indicator Clustering', fontsize=15, 
             color='#1f2937', fontweight='bold', pad=18)
ax.set_xlabel('Country', fontsize=11, color='#374151')
ax.set_ylabel('Economic Distance', fontsize=11, color='#374151')

ax.tick_params(axis='both', colors='#374151', labelsize=10)
for spine in ['top', 'right']:
    ax.spines[spine].set_visible(False)
for spine in ['left', 'bottom']:
    ax.spines[spine].set_color('#e5e7eb')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support