简单Python画折线图

#!/usr/bin/python3
# -*- coding: utf-8 -*-
# __author__ = "Mr.chen"
# Date: 2018/6/7

import json
import matplotlib.pyplot as plt

# 获取的监控数据,字典格式保存在文件中
new_dict = {}

with open('json.txt', 'r', encoding='utf-8') as json_f:
    f = json_f.read()
    new_dict = json.loads(f)
    print("加载入文件完成...")


# print(new_dict['dataPoints'])  # 结果是一个列表
#
# x = range(len(new_dict))
# plt.plot(x, new_dict['dataPoints'])

dict2 = []  # 横坐标
for i in range(0, 1445, 5):
    dict2.append(i)



# plt.plot([1, 3, 2, 4])  # 直接打印的结果是根据输入的列表生成的
# 输入的值默认为y轴数据
# 当输入两个列表值时,会将第一个认为是x轴数据
# 两个列表的长度需要一样
plt.plot(dict2, new_dict['dataPoints'])
# plt.plot([1,3,3,4], [1,4,9,16])
plt.ylabel('some numbers')
plt.show()

详细链接:http://www.datahub.top/coursedetail/?id=29

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值