-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
80 lines (68 loc) · 2.1 KB
/
Copy pathscript.py
File metadata and controls
80 lines (68 loc) · 2.1 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
import os
import sys
import matplotlib.pyplot as plt
import numpy as np
INPUT_FOLDER="/Users/i314050/work/paul_phd/input"
SEPARATOR = os.path.sep
points = []
#This is an object to store the X / Y values
class Entry:
xAxisValue = 0
yAxisValue = 0
def __init__(self, xAxis, yAxis):
self.xAxisValue = xAxis
self.yAxisValue = yAxis
def toString(self):
return "xAxis: " + str(self.xAxisValue) + " yAxis:" + str(self.yAxisValue)
def debug(self):
print(self.toString())
#This loads the files
def loadFiles():
for filename in os.listdir(INPUT_FOLDER):
if filename.endswith(".txt"):
readFile(INPUT_FOLDER + SEPARATOR + filename)
#This reads the files
def readFile(filename):
inputFile = open(filename, 'r')
content = inputFile.readlines()
print("Filename: " + filename + " length =" + str(len(content)))
for line in content:
data = line.split()
try:
entry = Entry(float(data[0]), float(data[1]))
entry2 = Entry(float(data[2]), float(data[3]))
points.append(entry)
points.append(entry2)
except ValueError:
print("Invalid line found: ")
print(" Filename: " + filename)
print(" Line: " + line)
print("Loaded - " + str(len(points)))
inputFile.close()
#This handles actually plotting the graph
def plotGraph():
print("Plotting graph: " +str(len(points)))
xValues = []
yValues = []
for point in points:
xValues.append(point.xAxisValue)
yValues.append(point.yAxisValue)
if len(xValues) != len(yValues):
print("Number of X Values does not match Y Values. Exiting")
sys.exit()
print("XValue length: " + str(len(xValues)))
print("YValue length: " + str(len(yValues)))
numPyXValues = np.array(xValues)
numPyYValues = np.array(yValues)
colors = (0,0,0)
area = np.pi*3
plt.scatter(numPyXValues, numPyYValues, s=area, c=colors, alpha=0.5)
plt.title('Scatter plot')
plt.xlabel('x')
plt.ylabel('y')
plt.show()
#This is the main method
if __name__ == '__main__':
print("Running script. Input=" + INPUT_FOLDER)
loadFiles()
plotGraph()