import os
import numpy as np
import random
import matplotlib.pyplot as plt
'''
log里的数据格式:
1次测量数据: IC1: ce111 cell2 …… cell36
IC2: ce111 cell2 …… cell36
……
IC7: ce111 cell2 …… cell36
2次测量数据: IC1: ce111 cell2 …… cell36
IC2: ce111 cell2 …… cell36
……
IC7: ce111 cell2 …… cell36
……
n次测量数据: IC1: ce111 cell2 …… cell36
IC2: ce111 cell2 …… cell36
……
IC7: ce111 cell2 …… cell36
'''
ic = 7
cell = 36
ad_count = 100
num_list = []
plot_line = 36
def save_log(pwd):
print("save_log")
my_log = pwd + '\\my_test.log'
flog = open(my_log,'w+')
for i in range(ic*ad_count):
my_list = [random.random() for cell_i in range(cell)]
my_str = ''
for float_num in my_list:
my_str = my_str + str(round(float_num,2)) + ' '
flog.write(my_str + '\n')
flog.close()
def get_log(pwd):
print("get_log")
my_log = pwd + '\\my_test.log'
flog = open(my_log,'r')
for line in flog:
my_str_list = line.split()
my_list = [float(my_str) for my_str in my_str_list]
for i in range(cell-len(my_list)):
my_list.append(0)
num_list.append(my_list)
flog.close()
def plot_log():
print("plot_log")
num_array = np.array(num_list)
for ic_i in range(ic):
for cell_i in range(cell):
plot_array = num_array[ic_i: :ic, cell_i]
plt.figure(ic_i*(cell/plot_line)+cell_i/plot_line+1)
plt.subplot(plot_line,1,cell_i%plot_line+1)
plt.plot(plot_array, color='red', linewidth=0.5, linestyle='-')
plt.xticks([])
plt.yticks([])
plt.ylabel(str(cell_i+1), fontsize=5, rotation='horizontal')
plt.title('IC' + str(ic_i+1) + ' analysis', y=-3)
plt.show()
if __name__ == '__main__':
pwd = os.getcwd()
save_log(pwd)
get_log(pwd)
plot_log()