Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # README:
- # This script works with both python2 and python3, BUT:
- # You will need matplotlib for this script to work. Install it by running
- # ~$ pip install matplotlib
- #
- # Note that some systems sudo to run pip!
- #
- # Usage: python audacityspectrum.py [file1.txt] [file2.txt] ...
- # OTHERWISE:
- # $ chmod +x audacityspectrum.py
- # $ ./audacityspectrum.py [file1.txt] [file2.txt] ...
- import matplotlib.pyplot as plt
- from sys import argv
- if len(argv) < 2:
- print("Usage: %s [spectrum1.txt] [spectrum2.txt] ..." % argv[0])
- exit(-1)
- X = []
- Y = []
- for filename in argv[1:]:
- x = []
- y = []
- try:
- with open(filename, 'r') as data:
- x_name, y_name = data.readline().strip("\n").split("\t")
- for line in data.read().split("\n"):
- if not line:
- break
- line = line.split("\t")
- x.append(float(line[0].replace(',', '.')))
- y.append(float(line[1].replace(',', '.')))
- X.append(x)
- Y.append(y)
- except Exception as e:
- print(e)
- exit(-1)
- plt.xlabel(x_name)
- plt.ylabel(y_name)
- plt.xscale('log')
- plt.yscale('linear')
- plt.grid(True)
- for i in range(len(argv) - 1):
- plt.subplot()
- plt.plot(X[i], Y[i])
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement