1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| import matplotlib.pyplot as plt import seaborn as sns
fig, axes = plt.subplots(2, 2, figsize=(14, 10))
ax1 = axes[0, 0] sns.lineplot(data=df, x='Date', y='Internet_Penetration (%)', hue='Urban_Rural', ci=None, ax=ax1) ax1.set_title("城乡互联网渗透率") ax1.legend(title='Urban/Rural')
ax2 = axes[0, 1] sns.scatterplot(data=df, x='GDP_Per_Capita (USD)', y='Digital_Investment (M USD)', hue='Country', ax=ax2, legend=False) ax2.set_title("数字投资与人均GDP的关系")
ax3 = axes[1, 0] sns.violinplot(data=df, x='Country', y='Internet_Penetration (%)', palette=colors, ax=ax3) ax3.set_title("各国互联网渗透率分布") ax3.tick_params(axis='x', rotation=45)
ax4 = axes[1, 1] investment_by_country = df.groupby('Country')['Digital_Investment (M USD)'].sum() top10 = investment_by_country.sort_values(ascending=False).head(10)
ax4.pie(top10, labels=top10.index, autopct='%1.1f%%', startangle=140, colors=colors[:10], wedgeprops={'edgecolor': 'white'}) ax4.set_title("国家数字投资占比")
plt.tight_layout() plt.show()
|