12345678910111213141516171819 |
- import matplotlib.pyplot as plt
- def plot_data_from_txt(file1, file2):
- with open(file1, 'r') as f1, open(file2, 'r') as f2:
- data1 = [float(line.strip()) for line in f1]
- data2 = [float(line.strip()) for line in f2]
- plt.figure()
- plt.plot(data1, label='Data from file1')
- plt.plot(data2, label='Data from file2')
- plt.xlabel('Index')
- plt.ylabel('Value')
- plt.title('Waveform of Data from Two Files')
- plt.legend()
- plt.show()
- plt.savefig('waveform.png')
- # Example usage
- plot_data_from_txt('datas_cpp.txt', 'datas_py.txt')
|