import re
import os
# import csv
#
# import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False #用来正常显示负号
def gather_source_data_files() -> list:
source_data_files = list()
name_pattern = re.compile(r'^data[0-9]*\.')
target_folder = os.path.dirname(os.path.abspath(__file__))
for file in os.listdir(target_folder):
if re.search(name_pattern, file):
source_data_files.append(os.path.join(target_folder, file))
return source_data_files
if __name__ == "__main__":
for file in gather_source_data_files():
source_data_frame = pd.read_csv(file)
# 消除重复数据
source_data_frame = source_data_frame.drop_duplicates(['datetime'])
# 转换字符为时间,不然字符太多,内存不够显示不出来
source_data_frame['datetime'] = source_data_frame['datetime'].astype('datetime64')
# source_data_frame = source_data_frame.set_index(['datetime'])
print(source_data_frame)
x = source_data_frame['datetime']
y1 = source_data_frame['data1']
y2 = source_data_frame['data2']
# 画子图,两行,一列,第一个
plt.subplot(2, 1, 1)
plt.plot(x, y1)
# 画子图,两行,一列,第二个
plt.subplot(2, 1, 2)
plt.plot(x, y2)
plt.xlabel(u'时间')
plt.ylabel('iops')
plt.show()
# 更改索引
source_data_frame = source_data_frame.set_index(['datetime'])
source_data_frame.plot()
plt.show()
原始数据:https://download.csdn.net/download/weixin_40292043/70026865