matplotlib绘图一例

该文章通过数据可视化展示了中国网上外卖用户从2015年至2023年的规模变化以及使用率的增长情况,以柱状图和折线图的形式呈现了关键数据点和趋势。
摘要由CSDN通过智能技术生成

matplotlib绘图

'''网上外卖用户规模及使用率'''

import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import pandas as pd

# 数据源自www.cnnic.net.cn。
l = [["2015/12", "1.14亿", "16.5%"], ["2016/6", "1.50亿", "21.1%"], ["2017/12", "3.43亿", "44.5%"], ["2018/12", "4.06亿", "49.0%"],
     ["2020/3", "3.98亿", "44.0%"], ["2020/12", "4.19亿", "42.3%"], ["2021/12", "5.44亿", "52.7%"], ["2022/12", "5.21亿", "48.8%"],
     ["2023/6", "5.35亿", "49.6%"]]
#去掉“亿”
for i in l:
     i[1] = float(i[1][:-1])
     i[2] = float(i[2][:-1])/100
# d['month'] = pd.to_datetime(d['month'])
df = pd.DataFrame(l, columns=['Year', 'Population', 'Proportion'])
x = df['Year']
y1 = df['Population']
y2 = df['Proportion']
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
plt.rcParams.update({'font.size': 12})
# plt.xticks(rotation=30)
plt.figure(figsize=(14, 8))
plt.subplot(111)
plt.bar(x, y1, 0.5, color='g', label='网上外卖用户数', )
for y,p in zip(df['Year'],df['Population']):
     plt.text(y, p, str(p), ha='center', va= 'bottom',fontsize=12)
# y's limit
plt.ylim(0,7)
plt.legend(loc='upper left')
plt.ylabel("单位:亿人", fontsize=12, loc="center")
plt.xticks(x)
# plt.set_xticklabels(sale.index)
plt.xlabel("年月", fontsize=12, loc="center")
# 在次坐标轴上绘制折线图
plt.twinx()
# ls is linestyle; marker here is diamond.
plt.plot(x, y2, ls='dotted', lw=2, color='b', marker='d', ms=10, mfc='k', label='网上外卖使用率')
plt.ylim(0, 1)
plt.legend(loc='upper right')
plt.title('\n网上外卖用户数及使用率\n', fontsize=26, loc='center', color='k')
plt.ylabel("", fontsize=20, loc="center")
# plt.savefig('./figure1.jpg', bbox_inches='tight')
plt.show()
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值