2026-rff_mp/ProninVV/aufgabe-1-data-structures/graphiki.py

63 lines
2.4 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 pandas as pd
import glob
import re
import os
import matplotlib.pyplot as plt
from matplotlib.ticker import AutoMinorLocator
import numpy as np
from scipy.interpolate import interp1d, CubicSpline
from scipy.optimize import curve_fit
from numpy.polynomial import Polynomial
folder_path = 'results'
# 2. Список размеров (500, 1000, 2000, 5000, 10000)
sizes = ['500', '1000', '2000', '5000', '10000']
for size in sizes:
files = glob.glob(os.path.join(folder_path, f'timedata_{size}_epochs_*.csv'))
if not files:
continue
# Читаем файлы
dfs = [pd.read_csv(f) for f in files]
# 1. Определяем, какие колонки текстовые (не числовые)
# Предполагаем, что во всех файлах они одинаковые
text_cols = dfs[0].select_dtypes(exclude=['number']).columns.tolist()
# 2. Объединяем и считаем среднее
# Группируем по текстовым колонкам, чтобы они остались в результате
if text_cols:
combined = pd.concat(dfs)
mean_df = combined.groupby(text_cols).mean().reset_index()
else:
# Если текста нет, просто среднее по строкам
mean_df = pd.concat(dfs).groupby(level=0).mean()
output_name = f'average_timedata_{size}.csv'
mean_df.to_csv(os.path.join(folder_path, output_name), index=False)
print(f"Файл {output_name} успешно создан")
# построение графика
# fig, ax = plt.subplots(figsize=(8, 5))
# ax.set_title("График зависимости фазы от частоты(сх5)")
# ax.set_xlabel("v, Hz")
# ax.set_ylabel("phi, rad")
# ax.grid(which="major", linewidth=1.5)
# ax.grid(which="minor", color="gray", linewidth=0.5)
# ax.xaxis.set_minor_locator(AutoMinorLocator())
# ax.yaxis.set_minor_locator(AutoMinorLocator())
# ax.axhline(y=0, color='black', linewidth=1, linestyle='-', alpha=0.7) # Ось X (U=0)
# ax.axvline(x=0, color='black', linewidth=1, linestyle='-', alpha=0.7) # Ось Y (B=0)
# ax.plot(1, 0, ">k", transform=ax.get_yaxis_transform(), clip_on=False)
# ax.plot(0, 1, "^k", transform=ax.get_xaxis_transform(), clip_on=False)
# ax.legend()
# plt.savefig('graphics\zadanie3.png', dpi=200)
# plt.savefig('graphics\zadanie3.eps', dpi=200)
# plt.show()