51 lines
1023 B
Python
Executable File
51 lines
1023 B
Python
Executable File
#!/usr/bin/env python
|
|
|
|
import sys
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
def parse_input(lines):
|
|
x_vals = []
|
|
y_vals = []
|
|
for line in lines:
|
|
line = line.strip()
|
|
if not line:
|
|
continue
|
|
parts = line.replace(',', ' ').split()
|
|
if len(parts) == 1:
|
|
y_vals.append(float(parts[0]))
|
|
x_vals.append(len(x_vals))
|
|
elif len(parts) >= 2:
|
|
x_vals.append(float(parts[0]))
|
|
y_vals.append(float(parts[1]))
|
|
else:
|
|
continue
|
|
|
|
return x_vals, y_vals
|
|
|
|
|
|
def parse_file(file):
|
|
with open(file, "r") as f:
|
|
lines = f.readlines()
|
|
return parse_input(lines)
|
|
|
|
|
|
def parse_stdin():
|
|
lines = sys.stdin.readlines()
|
|
return parse_input(lines)
|
|
|
|
|
|
def plot(x_vals, y_vals):
|
|
plt.plot(x_vals, y_vals)
|
|
plt.grid(True)
|
|
plt.show()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) == 2:
|
|
x_vals, y_vals = parse_file(sys.argv[1])
|
|
else:
|
|
x_vals, y_vals = parse_stdin()
|
|
|
|
plot(x_vals, y_vals)
|