plt.py 571 B

12345678910111213141516171819
  1. import matplotlib.pyplot as plt
  2. def plot_data_from_txt(file1, file2):
  3. with open(file1, 'r') as f1, open(file2, 'r') as f2:
  4. data1 = [float(line.strip()) for line in f1]
  5. data2 = [float(line.strip()) for line in f2]
  6. plt.figure()
  7. plt.plot(data1, label='Data from file1')
  8. plt.plot(data2, label='Data from file2')
  9. plt.xlabel('Index')
  10. plt.ylabel('Value')
  11. plt.title('Waveform of Data from Two Files')
  12. plt.legend()
  13. plt.show()
  14. plt.savefig('waveform.png')
  15. # Example usage
  16. plot_data_from_txt('datas_cpp.txt', 'datas_py.txt')