Files
MemMAPR-DZ/test.ipynb

96 lines
2.7 KiB
Plaintext
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.

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "a4654478",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"data = pd.read_csv('result.dat', sep=r'\\s+', header=None)\n",
"\n",
"n_cols = data.shape[1]\n",
"print(f\"Загружено {n_cols} столбцов.\")\n",
"\n",
"if n_cols < 3:\n",
" raise ValueError(\"Недостаточно столбцов (ожидалось минимум: t, φ, I_L)\")\n",
"\n",
"time = data[0]\n",
"\n",
"num_phi = n_cols - 2\n",
"print(f\"Обнаружено {num_phi} узлов φ.\")\n",
"\n",
"phi_cols = list(range(1, 1 + num_phi))\n",
"\n",
"colors = plt.cm.tab10(np.linspace(0, 1, 10))\n",
"\n",
"# ---------------------------------------------------------\n",
"# Графики φ₁…φ_N\n",
"# ---------------------------------------------------------\n",
"for idx, col in enumerate(phi_cols, start=1):\n",
" label = f'$\\\\phi_{idx}, В$'\n",
"\n",
" fig, ax = plt.subplots(figsize=(8, 4))\n",
"\n",
" ax.plot(time, data[col],\n",
" color=colors[idx % len(colors)],\n",
" linewidth=1.8,\n",
" label=label)\n",
"\n",
" ax.set_xlabel('$t$, с', fontsize=12)\n",
" ax.set_ylabel(label, fontsize=12)\n",
" ax.grid(True, linestyle='--', linewidth=0.5, alpha=0.7)\n",
"\n",
" fig.tight_layout()\n",
" #fig.savefig(f\"program-{idx}.png\", dpi=300)\n",
" plt.show()\n",
"\n",
"# ---------------------------------------------------------\n",
"# График тока I_L\n",
"# ---------------------------------------------------------\n",
"iL_col = n_cols - 1\n",
"\n",
"fig, ax = plt.subplots(figsize=(8, 4))\n",
"\n",
"ax.plot(time, data[iL_col],\n",
" color='black',\n",
" linewidth=1.8,\n",
" label='$I_L$')\n",
"\n",
"ax.set_xlabel('$t$, с', fontsize=12)\n",
"ax.set_ylabel('$I_L$, A', fontsize=12)\n",
"ax.grid(True, linestyle='--', linewidth=0.5, alpha=0.7)\n",
"\n",
"fig.tight_layout()\n",
"#fig.savefig(\"program-IL.png\", dpi=300)\n",
"plt.show()\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}