Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # README:
  5. # This script works with both python2 and python3, BUT:
  6. # You will need matplotlib for this script to work. Install it by running
  7. # ~$ pip install matplotlib
  8. #
  9. # Note that some systems sudo to run pip!
  10. #
  11. # Usage: python audacityspectrum.py [file1.txt] [file2.txt] ...
  12. # OTHERWISE:
  13. # $ chmod +x audacityspectrum.py
  14. # $ ./audacityspectrum.py [file1.txt] [file2.txt] ...
  15.  
  16. import matplotlib.pyplot as plt
  17. from sys import argv
  18.  
  19. if len(argv) < 2:
  20. print("Usage: %s [spectrum1.txt] [spectrum2.txt] ..." % argv[0])
  21. exit(-1)
  22.  
  23. X = []
  24. Y = []
  25.  
  26. for filename in argv[1:]:
  27. x = []
  28. y = []
  29. try:
  30. with open(filename, 'r') as data:
  31. x_name, y_name = data.readline().strip("\n").split("\t")
  32. for line in data.read().split("\n"):
  33. if not line:
  34. break
  35. line = line.split("\t")
  36. x.append(float(line[0].replace(',', '.')))
  37. y.append(float(line[1].replace(',', '.')))
  38.  
  39.  
  40. X.append(x)
  41. Y.append(y)
  42.  
  43. except Exception as e:
  44. print(e)
  45. exit(-1)
  46.  
  47.  
  48. plt.xlabel(x_name)
  49. plt.ylabel(y_name)
  50. plt.xscale('log')
  51. plt.yscale('linear')
  52. plt.grid(True)
  53.  
  54. for i in range(len(argv) - 1):
  55. plt.subplot()
  56. plt.plot(X[i], Y[i])
  57.  
  58. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement