Files
aisd/Lab2/plot.py
T
2025-05-06 19:02:00 +02:00

59 lines
1.9 KiB
Python

import matplotlib.pyplot as plt
def plot(header:str, first:list[int], second:list[int], log=False, labels=("Lista", "Drzewo BST")):
plt.figure(figsize=(10, 6))
plt.plot(range(1000,25001,1000), first, label=labels[0])
plt.plot(range(1000,25001,1000), second, label=labels[1])
plt.xlabel("Rozmiar tablicy")
plt.ylabel("Czas (ms)")
if log:
plt.yscale('log', base=2)
plt.title(header)
plt.legend()
plt.savefig(f"./charts/{header}.png")
if __name__ == "__main__":
with open('results.csv', 'r') as file:
data = file.read()
lines = data.split('\n')
headers = lines[0].split(',')
values = [line.split(',') for line in lines[1:]]
bstTimes = {
"build":[],
"search":[],
"delete":[]
}
listTimes = {
"build":[],
"search":[],
"delete":[]
}
for row in values:
if row[0] == 'BST':
bstTimes['build'].append(float(row[1]))
bstTimes['search'].append(float(row[2]))
bstTimes['delete'].append(float(row[3]))
elif row[0] == 'List':
listTimes['build'].append(float(row[1]))
listTimes['search'].append(float(row[2]))
listTimes['delete'].append(float(row[3]))
plot("Tworzenie", listTimes['build'], bstTimes['build'])
plot("Wyszukiwanie", listTimes['search'], bstTimes['search'], log=True)
plot("Usuwanie", listTimes['delete'], bstTimes['delete'])
with open("avl.csv", "r") as file:
data = file.read()
lines = data.split('\n')
headers = lines[0].split(',')
values = [line.split(',') for line in lines[1:-1]]
bstHeights = [int(x[0]) for x in values]
avlHeights = [int(x[1]) for x in values]
plot("AVl", bstHeights, avlHeights, log=True, labels=("Drzewo BST", "Drzewo AVL"))