-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetcoords.py
More file actions
61 lines (49 loc) · 1.88 KB
/
getcoords.py
File metadata and controls
61 lines (49 loc) · 1.88 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
import os
import matplotlib.pyplot as plt
import numpy as np
filespath = "/home/luca/Desktop/Analisi/modules/Data_measurements/Batch2"
px = []
py = []
pz = []
n_points_per_file = 8
n_files = 0
for filename in os.listdir(filespath):
if os.path.isfile(os.path.join(filespath, filename)):
print(filename)
n_files = n_files+1
with open(os.path.join(filespath, filename)) as file:
count = 0 # Reset the count for each file
for line in file:
if "point" in line:
line = line[45:] # Remove characters before the coordinates
coordinates = line.split()[:3] # Split by spaces and take the first three values
if len(coordinates) == 3:
x, y, z = map(float, coordinates)
px.append(x)
py.append(y)
pz.append(y)
plt.scatter(px, py, label='Scatter Plot', color='blue', marker='o')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.show()
distances_x = []
distances_y = []
for i in range(int(len(px)/n_points_per_file)):
distances_x.append(-1*px[i*n_points_per_file]+px[i*n_points_per_file+1]-2.)
distances_x.append(px[i*n_points_per_file+4]-px[i*n_points_per_file+5]-2.)
distances_y.append(-1*py[i*n_points_per_file+2]+py[i*n_points_per_file+3]-2.)
distances_y.append(py[i*n_points_per_file+6]-py[i*n_points_per_file+7]-2.)
# Create histograms for X and Y distances
plt.figure(figsize=(12, 4))
plt.subplot(1, 2, 1)
plt.hist(distances_x, bins=20, color='blue', edgecolor='black')
plt.xlabel('Distance along X-axis')
plt.ylabel('Frequency')
plt.title('Histogram of X Distances')
plt.subplot(1, 2, 2)
plt.hist(distances_y, bins=20, color='green', edgecolor='black')
plt.xlabel('Distance along Y-axis')
plt.ylabel('Frequency')
plt.title('Histogram of Y Distances')
plt.tight_layout()
plt.show()