poprawiony nagłowek na wykresie

This commit is contained in:
2026-02-19 11:13:57 +01:00
parent b53c7e7b1d
commit bf9c4596b8

View File

@@ -282,34 +282,29 @@ def calculate_impedance(u_cpx, i_cpx):
live_plot_fig = None
live_ax = None
live_lines = {}
live_data = {}
if args.live_plot:
plt.ion()
live_plot_fig, live_ax = plt.subplots(figsize=(8, 8), subplot_kw={'projection': 'polar'})
live_data = {'L1': ([], []), 'L2': ([], []), 'L3': ([], [])} # Kąty, Moduły
if args.live_plot == 'z':
live_ax.set_title('Podgląd wektorów impedancji na żywo')
line_angle_rad = math.radians(line_angle)
live_ax.plot([line_angle_rad, line_angle_rad], [0, Z_line_mag], color='k', linestyle='--', linewidth=2, label=f'Linia Z ({line_angle:.1f} deg)')
rmax = getattr(relay, 'Z3_R', getattr(relay, 'Z5_R', 20)) * 1.5
live_ax.set_rmax(rmax)
elif args.live_plot == 'u':
live_ax.set_title('Podgląd wektorów napięć na żywo')
data_max = max(d.max() for d in (u1_raw, u2_raw, u3_raw) if len(d) > 0)
live_ax.set_rmax(data_max * 1.2 if data_max > 0 else 1)
elif args.live_plot == 'i':
live_ax.set_title('Podgląd wektorów prądów na żywo')
data_max = max(d.max() for d in (i1_raw, i2_raw, i3_raw) if len(d) > 0)
live_ax.set_rmax(data_max * 1.2 if data_max > 0 else 1)
# Wspólna konfiguracja dla wszystkich wykresów wektorowych
live_lines['L1'], = live_ax.plot([], [], 'b.', markersize=7, label='L1')
live_lines['L2'], = live_ax.plot([], [], 'g.', markersize=7, label='L2')
live_lines['L3'], = live_ax.plot([], [], 'o', color='orange', markerfacecolor='none', markersize=7, label='L3')
live_lines['L1'], = live_ax.plot([], [], 'b-', linewidth=2, marker='o', label='L1')
live_lines['L2'], = live_ax.plot([], [], 'g-', linewidth=2, marker='o', label='L2')
live_lines['L3'], = live_ax.plot([], [], '-', color='orange', linewidth=2, marker='o', label='L3')
live_ax.legend(loc='upper right', fontsize=8)
live_ax.grid(True)
@@ -360,36 +355,36 @@ for i in range(N, len(t)):
# ===== Aktualizacja podglądu na żywo =====
if args.live_plot and live_plot_fig:
phasors = {}
if args.live_plot == 'z':
z1_mag, z1_ang = math.sqrt(z1_r**2 + z1_x**2), math.atan2(z1_x, z1_r)
z2_mag, z2_ang = math.sqrt(z2_r**2 + z2_x**2), math.atan2(z2_x, z2_r)
z3_mag, z3_ang = math.sqrt(z3_r**2 + z3_x**2), math.atan2(z3_x, z3_r)
if z1_mag > 0.01: live_data['L1'][0].append(z1_ang); live_data['L1'][1].append(z1_mag)
if z2_mag > 0.01: live_data['L2'][0].append(z2_ang); live_data['L2'][1].append(z2_mag)
if z3_mag > 0.01: live_data['L3'][0].append(z3_ang); live_data['L3'][1].append(z3_mag)
phasors['L1'] = (math.atan2(z1_x, z1_r), math.sqrt(z1_r**2 + z1_x**2))
phasors['L2'] = (math.atan2(z2_x, z2_r), math.sqrt(z2_r**2 + z2_x**2))
phasors['L3'] = (math.atan2(z3_x, z3_r), math.sqrt(z3_r**2 + z3_x**2))
elif args.live_plot == 'u':
u1_mag, u1_ang = abs(U1_cpx), np.angle(U1_cpx)
u2_mag, u2_ang = abs(U2_cpx), np.angle(U2_cpx)
u3_mag, u3_ang = abs(U3_cpx), np.angle(U3_cpx)
live_data['L1'][0].append(u1_ang); live_data['L1'][1].append(u1_mag)
live_data['L2'][0].append(u2_ang); live_data['L2'][1].append(u2_mag)
live_data['L3'][0].append(u3_ang); live_data['L3'][1].append(u3_mag)
phasors['L1'] = (np.angle(U1_cpx), abs(U1_cpx))
phasors['L2'] = (np.angle(U2_cpx), abs(U2_cpx))
phasors['L3'] = (np.angle(U3_cpx), abs(U3_cpx))
elif args.live_plot == 'i':
i1_mag, i1_ang = abs(I1_cpx), np.angle(I1_cpx)
i2_mag, i2_ang = abs(I2_cpx), np.angle(I2_cpx)
i3_mag, i3_ang = abs(I3_cpx), np.angle(I3_cpx)
live_data['L1'][0].append(i1_ang); live_data['L1'][1].append(i1_mag)
live_data['L2'][0].append(i2_ang); live_data['L2'][1].append(i2_mag)
live_data['L3'][0].append(i3_ang); live_data['L3'][1].append(i3_mag)
phasors['L1'] = (np.angle(I1_cpx), abs(I1_cpx))
phasors['L2'] = (np.angle(I2_cpx), abs(I2_cpx))
phasors['L3'] = (np.angle(I3_cpx), abs(I3_cpx))
# Wspólna aktualizacja dla wszystkich wykresów wektorowych
live_lines['L1'].set_data(live_data['L1'])
live_lines['L2'].set_data(live_data['L2'])
live_lines['L3'].set_data(live_data['L3'])
# Aktualizacja wektorów
for phase in ['L1', 'L2', 'L3']:
angle, mag = phasors[phase]
live_lines[phase].set_data([angle, angle], [0, mag])
live_ax.set_title(f'Podgląd na żywo (próbka {i+1}/{len(t)})')
# Aktualizacja tytułu i odświeżenie wykresu
quantity_text = {
'z': 'Impedancja (Z)',
'u': 'Napięcie (U)',
'i': 'Prąd (I)'
}.get(args.live_plot, '')
live_ax.set_title(
f'{quantity_text} | Podgląd na żywo (próbka {i+1}/{len(t)}, czas: {t[i]:.4f} s)',
fontsize=10
)
live_plot_fig.canvas.draw()
live_plot_fig.canvas.flush_events()