安装库
pip install matplotlib numpy
代码
import re
import numpy as np
import matplotlib.pyplot as plt
file_path = 'desktop\123.DAT'
with open(file_path, 'r') as file:
log_text = file.read()
data = []
pattern = r"AverDIFF:(-?\d+)"
matches = re.findall(pattern, log_text)
for match in matches:
data.append(int(match))
total_count = len(data)
print(f"总的数据个数: {total_count}")
filtered_data = [d for d in data if d < -2000 or d > 2000]
filtered_count = len(filtered_data)
print(f"异常数据个数: {filtered_count}")
if filtered_count > 0:
print(f"异常数据: {filtered_data}")
filtered_data_array = [d for d in data if d not in filtered_data]
filtered_data_array_count = len(filtered_data_array)
print(f"正常数据个数: {filtered_data_array_count}")
if not filtered_data_array:
print("没有找到符合条件的AverDIFF数据")
else:
filtered_data_array = np.array(filtered_data_array)
plt.figure(figsize=(12, 6))
plt.plot(filtered_data_array, marker='o')
plt.title("Filtered AverDIFF Waveform")
plt.xlabel("Index")
plt.ylabel("AverDIFF Value")
plt.xlim(0, len(filtered_data_array) + 10)
plt.grid()
plt.show()