#!/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()
简单Python画折线图
最新推荐文章于 2024-06-14 21:05:29 发布