-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_plot.py
More file actions
57 lines (46 loc) · 2.23 KB
/
test_plot.py
File metadata and controls
57 lines (46 loc) · 2.23 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
import sys
import pandas as pd
import matplotlib.pyplot as plt
def plot_data(filenames):
# Initialize a single figure with two subplots (top and bottom)
fig, (ax_top, ax_bottom) = plt.subplots(2, 1, sharex=True, figsize=(7, 5))
# Process each file
for filename in filenames:
try:
# Load the data file into a DataFrame
df = pd.read_csv(filename, delim_whitespace=True)
# Check if 'time' column is present
if 'time' not in df.columns:
print(f"Error: 'time' column is missing in file '{filename}'. Skipping this file.")
continue
# Set 'time' as the index for the plot
df.set_index('time', inplace=True)
# Split columns into top and bottom based on the prefix
top_columns = [col for col in df.columns if col.startswith("T_")]
bottom_columns = [col for col in df.columns if col.startswith("B_")]
# Plot top columns
if top_columns:
df[top_columns].plot(ax=ax_top, title="Top Data Plot", label=filename, legend=True)
ax_top.set_ylabel("Top Data Values")
ax_top.grid(True)
# Plot bottom columns
if bottom_columns:
df[bottom_columns].plot(ax=ax_bottom, title="Bottom Data Plot", label=filename, legend=True)
ax_bottom.set_ylabel("Bottom Data Values")
ax_bottom.grid(True)
except FileNotFoundError:
print(f"Error: File '{filename}' not found. Skipping this file.")
except pd.errors.EmptyDataError:
print(f"Error: The file '{filename}' is empty. Skipping this file.")
except Exception as e:
print(f"An error occurred with file '{filename}': {e}. Skipping this file.")
# Set shared x-label and layout adjustments
plt.xlabel("Time")
plt.tight_layout(rect=[0, 0, 1, 0.96]) # Adjust layout to fit the main title
plt.show()
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python plot_data.py <filename1> <filename2> ...")
else:
filenames = sys.argv[1:] # List of all provided filenames
plot_data(filenames)