-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualPlot.py
More file actions
53 lines (41 loc) · 1.61 KB
/
Copy pathvisualPlot.py
File metadata and controls
53 lines (41 loc) · 1.61 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
import os
import pandas as pd
import matplotlib.pyplot as plt
OUTPUT_DIR = "images"
def backup_existing_pdf(filename):
if os.path.exists(filename):
base, ext = os.path.splitext(filename)
i = 1
while os.path.exists(f"{base}_{i}{ext}"):
i += 1
os.rename(filename, f"{base}_{i}{ext}")
print(f"Renamed existing file to: {base}_{i}{ext}")
def plotExperiment(experiment):
data_file = f"{experiment}.dat"
output_file = f'{OUTPUT_DIR}/{experiment}.pdf'
# Load the tab-separated file (skip comment lines)
df = pd.read_csv(f'build/{data_file}', sep='\t', comment='#', header=None, names=['Event', 'Duration'])
# Clean up event names
df['Event'] = df['Event'].str.strip('"').str.strip()
# # Optional: sort by duration descending
# df = df.sort_values(by='Duration', ascending=False)
# Plot vertical bar chart
plt.figure(figsize=(14, 6))
bars = plt.bar(df['Event'], df['Duration'], color='steelblue')
for bar in bars:
yval = bar.get_height() # Get the height of each bar (the value)
plt.text(bar.get_x() + bar.get_width() / 2, yval, round(yval, 2), ha='center', va='bottom', fontsize=10)
plt.ylabel('Duration (ms)')
plt.xlabel('Event')
# plt.title('Event Durations')
# Rotate x-axis labels for better readability
plt.xticks(rotation=45, ha='right')
backup_existing_pdf(output_file)
plt.tight_layout()
plt.savefig(output_file, dpi=300)
plt.show()
if (__name__ == "__main__"):
size=2000
experiments = [f"exnn_binary_profile_{size}"]
for exp in experiments:
plotExperiment(exp)