赞
踩
rate = round(y1[i+1]/y1[i] - 1, 2)
y2.append(rate)
fig = plt.figure(figsize=(10, 8), facecolor=‘#ff33ff’)
plt.rcParams[‘font.sans-serif’] = [‘STKAITI’]
plt.rcParams[‘axes.unicode_minus’] = False
plt.rcParams[‘axes.facecolor’] = ‘#cc00ff’
ax1 = fig.add_subplot(111)
plt.title(‘销售量及其增长率图示’, color=‘#ffff00’, fontsize=25, y=1.04)
plt.xticks(x, [‘1月’, ‘2月’, ‘3月’, ‘4月’, ‘5月’, ‘6月’, ‘7月’], color=‘#ffff00’, fontsize=15)
plt.xlabel(‘月份’, color=‘#ff0033’, fontsize=15)
plt.yticks(color=‘#B22222’, fontsize=15)
ax1.bar(x, y1, color=‘#33ff66’, label=‘left’)
ax1.set_ylabel(‘销售量(件)’, color=‘#66ff00’, fontsize=20)
ax2 = ax1.twinx()
ax2.plot(x, y2, color=‘#3399ff’, linestyle=‘–’, marker=‘o’, linewidth=2)
ax2.set_ylabel(“增长率”, color=‘#66ff00’, fontsize=20)
ax2.tick_params(axis=‘y’, color=‘green’, labelsize=15, labelcolor=‘#B22222’)
for a, b in zip(x, y2):
plt.text(a, b+0.02, ‘%.2f’ % b, ha=‘center’, va=‘bottom’, fontsize=15, color=‘red’)
plt.show()
图像效果如下图:
本次分享就到这里,小啾感谢您的关注与支持!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。