From f387b9020b7dc5dc84cb88de917f8ca9666fc5ef Mon Sep 17 00:00:00 2001 From: KislyuninED Date: Thu, 14 May 2026 01:06:33 +0000 Subject: [PATCH] [1] create bar charts for experiment results --- .../docks/data/1-st-exercize/plot_results.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 KislyuninED/docks/data/1-st-exercize/plot_results.py diff --git a/KislyuninED/docks/data/1-st-exercize/plot_results.py b/KislyuninED/docks/data/1-st-exercize/plot_results.py new file mode 100644 index 0000000..e683d15 --- /dev/null +++ b/KislyuninED/docks/data/1-st-exercize/plot_results.py @@ -0,0 +1,35 @@ +import pandas as pd +import matplotlib.pyplot as plt +import numpy as np + +df = pd.read_csv('results.csv') +mean_df = df.groupby(['Structure','Mode','Operation'])['Time_sec'].mean().reset_index() + +fig, axes = plt.subplots(1, 3, figsize=(14,5)) +operations = ['insert','find','delete'] +titles = ['Insertion', 'Search', 'Deletion'] + +for ax, op, title in zip(axes, operations, titles): + subset = mean_df[mean_df['Operation'] == op] + structures = subset['Structure'].unique() + x = np.arange(len(structures)) + width = 0.35 + random_vals = [] + sorted_vals = [] + for s in structures: + r = subset[(subset['Structure']==s) & (subset['Mode']=='random')]['Time_sec'].values + s_vals = subset[(subset['Structure']==s) & (subset['Mode']=='sorted')]['Time_sec'].values + random_vals.append(r[0] if len(r) else 0) + sorted_vals.append(s_vals[0] if len(s_vals) else 0) + ax.bar(x - width/2, random_vals, width, label='random') + ax.bar(x + width/2, sorted_vals, width, label='sorted') + ax.set_xticks(x) + ax.set_xticklabels(structures) + ax.set_ylabel('Time (seconds)') + ax.set_title(title) + ax.legend() + +plt.tight_layout() +plt.savefig('performance.png', dpi=150) +plt.show() +print("График сохранён (performance.png)") \ No newline at end of file