2026-rff_mp/konnovaea/make_lab2_plots.py

94 lines
3.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import matplotlib.pyplot as plt
import os
os.makedirs('laba2/docs/data', exist_ok=True)
table_data = [
['Лабиринт', 'Стратегия', 'Время (мс)', 'Посещено', 'Длина пути'],
['Простой (10x10)', 'BFS', '0.037', '11', '6'],
['Простой (10x10)', 'DFS', '0.016', '9', '8'],
['Простой (10x10)', 'A*', '0.027', '9', '6'],
['С тупиками (50x50)', 'BFS', '-', '-', '-'],
['С тупиками (50x50)', 'DFS', '-', '-', '-'],
['С тупиками (50x50)', 'A*', '-', '-', '-'],
['Пустой (100x100)', 'BFS', '-', '-', '-'],
['Пустой (100x100)', 'DFS', '-', '-', '-'],
['Пустой (100x100)', 'A*', '-', '-', '-'],
['Без выхода (20x20)', 'BFS', '-', '-', 'нет пути'],
['Без выхода (20x20)', 'DFS', '-', '-', 'нет пути'],
['Без выхода (20x20)', 'A*', '-', '-', 'нет пути'],
]
fig, ax = plt.subplots(figsize=(12, 5))
ax.axis('off')
table = ax.table(cellText=table_data, loc='center', cellLoc='center', colWidths=[0.2, 0.13, 0.13, 0.13, 0.13])
table.auto_set_font_size(False)
table.set_fontsize(10)
table.scale(1, 1.8)
for i in range(5):
table[(0, i)].set_facecolor('#4472C4')
table[(0, i)].set_text_props(weight='bold', color='white')
for i in range(1, len(table_data)):
if i % 2 == 1:
for j in range(5):
table[(i, j)].set_facecolor('#E8F0FE')
else:
for j in range(5):
table[(i, j)].set_facecolor('#FFFFFF')
plt.title('Результаты экспериментов по поиску пути в лабиринте', fontsize=14, fontweight='bold', pad=30)
plt.savefig('laba2/docs/data/maze_table_results.png', dpi=200, bbox_inches='tight', facecolor='white')
plt.close()
fig, ax = plt.subplots(figsize=(8, 5))
algorithms = ['BFS', 'DFS', 'A*']
time_data = [0.037, 0.016, 0.027]
bars = ax.bar(algorithms, time_data, color=['#3498db', '#e74c3c', '#2ecc71'])
ax.set_ylabel('Время (мс)')
ax.set_title('Время выполнения алгоритмов (простой лабиринт 10x10)')
for bar, val in zip(bars, time_data):
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 0.001, f'{val:.3f}', ha='center', va='bottom')
plt.savefig('laba2/docs/data/maze_time_graph.png', dpi=150, bbox_inches='tight')
plt.close()
fig, ax = plt.subplots(figsize=(8, 5))
visited_data = [11, 9, 9]
bars = ax.bar(algorithms, visited_data, color=['#3498db', '#e74c3c', '#2ecc71'])
ax.set_ylabel('Количество клеток')
ax.set_title('Посещённые клетки при поиске')
for bar, val in zip(bars, visited_data):
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 0.3, str(val), ha='center', va='bottom')
plt.savefig('laba2/docs/data/maze_visited_graph.png', dpi=150, bbox_inches='tight')
plt.close()
fig, ax = plt.subplots(figsize=(8, 5))
path_data = [6, 8, 6]
bars = ax.bar(algorithms, path_data, color=['#3498db', '#e74c3c', '#2ecc71'])
ax.set_ylabel('Длина пути (шагов)')
ax.set_title('Длина найденного пути')
for bar, val in zip(bars, path_data):
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 0.3, str(val), ha='center', va='bottom')
plt.savefig('laba2/docs/data/maze_path_graph.png', dpi=150, bbox_inches='tight')
plt.close()