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 numpy as np
plt.rcParams['font.sans-serif'] = ['Arial Unicode MS'] plt.rcParams['axes.unicode_minus'] = False
months = [f'{m}月' for m in range(1, 13)] online = [120, 135, 148, 160, 155, 170, 185, 190, 175, 195, 210, 230] offline = [80, 75, 82, 78, 85, 72, 68, 70, 75, 65, 60, 55] total = [o + f for o, f in zip(online, offline)]
fig, axes = plt.subplots(2, 2, figsize=(14, 10))
axes[0, 0].plot(months, online, 'b-o', label='线上') axes[0, 0].plot(months, offline, 'r-s', label='线下') axes[0, 0].set_title('线上vs线下销售趋势') axes[0, 0].legend() axes[0, 0].set_ylabel('销售额(万元)')
axes[0, 1].bar(months, online, label='线上', alpha=0.8) axes[0, 1].bar(months, offline, bottom=online, label='线下', alpha=0.8) axes[0, 1].set_title('月度销售构成') axes[0, 1].legend()
axes[1, 0].pie([sum(online), sum(offline)], labels=['线上', '线下'], autopct='%1.1f%%', colors=['#4CAF50', '#FF9800']) axes[1, 0].set_title('全年销售渠道占比')
axes[1, 1].scatter(online, offline, s=100, alpha=0.6, c='steelblue') axes[1, 1].set_xlabel('线上销售额(万元)') axes[1, 1].set_ylabel('线下销售额(万元)') axes[1, 1].set_title('线上vs线下相关性')
plt.tight_layout() plt.savefig('ecommerce_report.png', dpi=150, bbox_inches='tight') plt.show()
|