python操作matplotlib画折线图显示数据

本文想说的是折线点的地方显示数据纵坐标数据

利用:plt.text() 方法

废话不多说,直接上代码:

# encoding=utf-8
import matplotlib.pyplot as plt

# 月份
x1 = ['2017-01', '2017-02', '2017-03', '2017-04', '2017-05', '2017-06', '2017-07', '2017-08',
      '2017-09', '2017-10', '2017-11', '2017-12']

# 体重
y1 = [86, 85, 84, 80, 75, 70, 70, 74, 78, 70, 74, 80]

# 设置画布大小
plt.figure(figsize=(16, 4))

# 标题
plt.title("my weight")

# 数据
plt.plot(x1, y1, label='weight changes', linewidth=3, color='r', marker='o',
         markerfacecolor='blue', markersize=20)

# 横坐标描述
plt.xlabel('month')

# 纵坐标描述
plt.ylabel('weight')

# 设置数字标签
for a, b in zip(x1, y1):
    plt.text(a, b, b, ha='center', va='bottom', fontsize=20)

plt.legend()
plt.show()

效果:


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值