-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_dat.py
127 lines (103 loc) · 2.81 KB
/
read_dat.py
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
120
121
122
123
124
125
126
127
import csv
import matplotlib.pyplot as plt
import numpy as np
# Open the CSV file
with open('./new_data/tri_blink_signal_100Hz_2ms_delay_20ms.Dat', 'r') as file:
# Create a CSV reader object
csv_reader = csv.reader(file)
time = []
x = []
y = []
sigma = []
diffs = []
diffs2 = []
i=0
ts = 0.002
# Iterate over each row in the CSV file
for row in (csv_reader):
# Assuming each row has 4 columns
if float(row[3])>1:
time.append(float(row[0]))
x.append(float(row[1]))
y.append(float(row[2]))
sigma.append(float(row[3]))
i+=1
diffs = np.diff(sigma)
diffs = np.insert(diffs, 0, diffs[0])
diffs2 = np.diff(diffs)
diffs2 = np.insert(diffs2, 0, diffs2[0])
start = 1300
end = 1400
# time = time[start:end]
# x = x[start:end]
# y = y[start:end]
# sigma = sigma[start:end]
# diffs = diffs[start:end]
# diffs2 = diffs2[start:end]
# x = []
# y = []
# sigma = []
# x = x_temp.copy()
# y = y_temp.copy()
# sigma = sigma_temp.copy()
# time = time_temp.copy()
# print(len(x), len(y), len(sigma))
# Create subplots
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, figsize=(10, 8), sharex=True)
# Plot X data
ax1.plot(time, x, label='X', color='r')
ax1.set_ylabel('X Value')
ax1.set_title('Data Plots')
ax1.grid(True)
ax1.legend()
# Plot Y data
ax2.plot(time, y, label='Y', color='g')
ax2.set_ylabel('Y Value')
ax2.grid(True)
ax2.legend()
# Plot Sigma data
ax3.plot(time, sigma, label='Sigma', color='b')
ax3.set_xlabel('Time')
ax3.set_ylabel('Sigma Value')
ax3.grid(True)
ax3.legend()
# # Plot diff data
# ax4.plot(time, diffs, label='Sigma', color='k')
# ax4.set_xlabel('Time')
# ax4.set_ylabel('diff Value')
# ax4.grid(True)
# ax4.legend()
# # Plot diff data
# ax5.plot(time, diffs2, label='Sigma', color='k')
# ax5.set_xlabel('Time')
# ax5.set_ylabel('diff2 Value')
# ax5.grid(True)
# ax5.legend()
plt.tight_layout()
# plt.show()
plt.figure(figsize=(8, 6))
scatter = plt.scatter(x, y, marker='o', label='Data', s=5,c=sigma, cmap='viridis', alpha=0.75)
plt.xlabel('X')
plt.ylabel('Y')
plt.title('X vs Y Data')
plt.xlim([-2.25, 2.25])
plt.ylim([-2.25, 2.25])
plt.grid(True)
plt.legend()
# Add annotations for indicating the color scale
# Add a color bar indicating the magnitude scale
cbar = plt.colorbar(scatter)
cbar.set_label('Magnitude')
# Plot the histograms
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 8), sharex=True)
ax1.hist(x, bins=30, color='skyblue', edgecolor='black') # Adjust the number of bins as needed
ax1.set_xlabel('X')
ax1.set_ylabel('Frequency')
ax1.set_title('Histogram of X')
ax1.grid(True)
ax2.hist(y, bins=30, color='skyblue', edgecolor='black') # Adjust the number of bins as needed
ax2.set_xlabel('Y')
ax2.set_ylabel('Frequency')
ax2.set_title('Histogram of Y')
ax2.grid(True)
plt.show()