Repository navigation
Expand file tree
/
Copy pathpltfiles.py
More file actions
executable file
·119 lines (107 loc) · 3.5 KB
/
Copy pathpltfiles.py
File metadata and controls
executable file
·119 lines (107 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python
def is_float(string):
try:
float(string)
return True
except ValueError:
return False
def readFile(fileName):
import sys
try:
ifile = open(fileName, "r")
except:
sys.exit(fileName + " does not exist. ")
x = []
y = []
for (index, string) in enumerate(ifile):
string = string.replace(",", " ")
a = string.split()
if (is_float(a[0])):
x.append(float(a[0]))
y.append(float(a[1]))
else:
continue
return x, y
def main():
import sys
import os
import matplotlib.pyplot as plt
if (len(sys.argv) == 1):
print "Input file name as arguments. "
return -1
else:
colors = ["bo", 'ro', 'co', 'mo', 'go']
if (len(sys.argv) > len(colors)+1):
print "Too many files to plot. "
return -1
fileNames = []
for i in range(1, len(sys.argv)):
fileNames.append(sys.argv[i])
for i in range(len(fileNames)):
if (not os.path.exists(fileNames[i])):
print fileNames[i] + " does not exist."
return -1
xLists = []
yLists = []
for i in range(len(fileNames)):
x, y = readFile(fileNames[i])
xLists.append(x)
yLists.append(y)
xmin = min(xLists[0])
xmax = max(xLists[0])
ymin = min(yLists[0])
ymax = max(yLists[0])
for i in range(len(xLists)):
min_temp = min(xLists[i])
max_temp = max(xLists[i])
if (xmin > min_temp):
xmin = min_temp
if (xmax < max_temp):
xmax = max_temp
for i in range(len(yLists)):
min_temp = min(yLists[i])
max_temp = max(yLists[i])
if (ymin > min_temp):
ymin = min_temp
if (ymax < max_temp):
ymax = max_temp
xdiff = xmax - xmin
ydiff = ymax - ymin
ymin = ymin - 0.1*ydiff
ymax = ymax + 0.1*ydiff
xmin = xmin - 0.05*xdiff
xmax = xmax + 0.05*xdiff
if (len(xLists) == 1):
plt.plot(xLists[0], yLists[0], colors[0])
plt.xlim(xmin, xmax)
plt.ylim(ymin, ymax)
plt.grid()
plt.show()
elif(len(xLists) == 2):
plt.plot(xLists[0], yLists[0], colors[0], xLists[1], yLists[1], colors[1])
plt.xlim(xmin, xmax)
plt.ylim(ymin, ymax)
plt.grid()
plt.show()
elif(len(xLists) == 3):
plt.plot(xLists[0], yLists[0], colors[0], xLists[1], yLists[1], colors[1], xLists[2], yLists[2], colors[2])
plt.xlim(xmin, xmax)
plt.ylim(ymin, ymax)
plt.grid()
plt.show()
elif(len(xLists) == 4):
plt.plot(xLists[0], yLists[0], colors[0], xLists[1], yLists[1], colors[1], xLists[2], yLists[2], colors[2], xLists[3], yLists[3], colors[3])
plt.xlim(xmin, xmax)
plt.ylim(ymin, ymax)
plt.grid()
plt.show()
elif(len(xLists) == 5):
plt.plot(xLists[0], yLists[0], colors[0], xLists[1], yLists[1], colors[1], xLists[2], yLists[2], colors[2], xLists[3], yLists[3], colors[3], xLists[4], yLists[4], colors[4])
plt.xlim(xmin, xmax)
plt.ylim(ymin, ymax)
plt.grid()
plt.show()
return 0
if __name__ == "__main__":
import sys
sys.exit(main())