2024-heraklion-parallel-python/exercises/exerciseA/plot.py

26 lines
693 B
Python
Raw Normal View History

2024-08-29 11:19:39 +02:00
import os
import numpy as np
import matplotlib.pyplot as plt
# IO: This loads the timings for you
threads, timings = [], []
for file in os.listdir('timings'):
with open(f'timings/{file}', 'r') as f:
n, t = f.read().strip().split(',')
2024-08-30 11:15:44 +02:00
if n != 'None':
threads.append(int(n))
timings.append(float(t))
2024-08-29 11:19:39 +02:00
threads = np.array(threads)
timings = np.array(timings)
print('This is the data I loaded: threads =', threads, ', timings =',timings)
fig, axs = plt.subplots()
2024-08-30 11:15:44 +02:00
axs.scatter(x=threads, y=timings, color = 'hotpink', marker = '*')
axs.set_xlabel('Number of threads')
axs.set_ylabel('Timing [s]')
axs.grid()
2024-08-29 11:19:39 +02:00
2024-08-30 11:15:44 +02:00
plt.savefig('threads_v_timings', dpi=300)