papier pgraph
This commit is contained in:
parent
b9eeff6ac4
commit
4363b6ec29
86
durchschl-papier-graph.py
Normal file
86
durchschl-papier-graph.py
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
from matplotlib.colors import LinearSegmentedColormap
|
||||||
|
|
||||||
|
def analyze_paper_breakdown(lengths, voltages, ed_standard_values):
|
||||||
|
"""
|
||||||
|
Analysiert die Durchschlageigenschaften von Papier.
|
||||||
|
Zeigt Spannung und Feldstärke mit passenden Farben.
|
||||||
|
Farbliche Darstellung der Fläche zwischen Realwert und 5 kV/mm mit glatterem Verlauf.
|
||||||
|
Hervorhebung des ED-Real-Verlaufs im unteren Graphen.
|
||||||
|
"""
|
||||||
|
|
||||||
|
lengths = np.array(lengths)
|
||||||
|
voltages = np.array(voltages)
|
||||||
|
ed_real = voltages / lengths
|
||||||
|
|
||||||
|
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 8), sharex=True)
|
||||||
|
|
||||||
|
# Farben für die Standardwerte definieren
|
||||||
|
colors = ['red', 'green', 'purple', 'orange', 'brown', 'cyan', 'magenta', 'olive']
|
||||||
|
if len(ed_standard_values) > len(colors):
|
||||||
|
import itertools
|
||||||
|
colors = list(itertools.islice(itertools.cycle(colors), len(ed_standard_values)))
|
||||||
|
|
||||||
|
# Farbpalette für den Verlauf erstellen (Grün zu Dunkelrot)
|
||||||
|
cmap = LinearSegmentedColormap.from_list("mycmap", ["green", "darkred"], N=500) #5x mehr Stufen
|
||||||
|
|
||||||
|
# Spannung plotten
|
||||||
|
ax1.plot(lengths, voltages, label="U (gemessen)", marker='o', linestyle='-', color='blue')
|
||||||
|
|
||||||
|
for i, ed_standard in enumerate(ed_standard_values):
|
||||||
|
u_erwartung = lengths * ed_standard
|
||||||
|
ax1.plot(lengths, u_erwartung, label=f"U (Erwartung, {ed_standard} kV/mm)", marker='x', linestyle='--', color=colors[i])
|
||||||
|
|
||||||
|
if ed_standard == 5:
|
||||||
|
deviation = u_erwartung - voltages
|
||||||
|
# Farbliche Darstellung der Fläche zwischen Realwert und 5 kV/mm mit glatterem Verlauf
|
||||||
|
for k in range(len(lengths)):
|
||||||
|
if ed_real[k] > 5:
|
||||||
|
rel_dist = (ed_real[k] - 5)
|
||||||
|
else:
|
||||||
|
rel_dist = (5 - ed_real[k])
|
||||||
|
|
||||||
|
color_index = min(499, int(rel_dist * 250)) #Angepasst an die erhöhte Stufenzahl
|
||||||
|
|
||||||
|
if 4 <= ed_real[k] <= 6:
|
||||||
|
if deviation[k] > 0:
|
||||||
|
ax1.fill_between(lengths[k:k+2], voltages[k:k+2], u_erwartung[k:k+2], color=cmap(color_index), alpha=0.5, zorder=5)
|
||||||
|
elif deviation[k] < 0:
|
||||||
|
ax1.fill_between(lengths[k:k+2], u_erwartung[k:k+2], voltages[k:k+2], color=cmap(color_index), alpha=0.5, zorder=5)
|
||||||
|
|
||||||
|
ax1.set_ylabel("Spannung [kV]")
|
||||||
|
ax1.set_title("Durchschlageigenschaften in Abhängigkeit von Materialstärke")
|
||||||
|
|
||||||
|
# Legende anpassen (Duplikate entfernen)
|
||||||
|
handles1, labels1 = ax1.get_legend_handles_labels()
|
||||||
|
by_label = dict(zip(labels1, handles1))
|
||||||
|
ax1.legend(by_label.values(), by_label.keys(), loc='upper left')
|
||||||
|
|
||||||
|
ax1.grid(True)
|
||||||
|
|
||||||
|
# Durchschlagsfeldstärke plotten MIT Hervorhebung
|
||||||
|
ax2.plot(lengths, ed_real, label="ED (gemessen)", marker='s', color='blue', linestyle='-', linewidth=3, zorder=10) #Dickere Linie, oberste Ebene
|
||||||
|
|
||||||
|
for i, ed_standard in enumerate(ed_standard_values):
|
||||||
|
ax2.plot(lengths, np.full_like(lengths, ed_standard), label=f"ED (Erwartung, {ed_standard} kV/mm)", linestyle='--', color=colors[i])
|
||||||
|
|
||||||
|
ax2.set_xlabel("Materialstärke [mm]")
|
||||||
|
ax2.set_ylabel("Durchschlagsfeldstärke [kV/mm]")
|
||||||
|
ax2.legend(loc='lower left')
|
||||||
|
ax2.grid(True)
|
||||||
|
|
||||||
|
fig.tight_layout()
|
||||||
|
return fig
|
||||||
|
|
||||||
|
# Beispieldaten
|
||||||
|
papier_lengths = [2, 3, 4, 5]
|
||||||
|
papier_voltages = [11, 15.1, 16.6, 21.6]
|
||||||
|
ed_standard_values = [4, 5, 6]
|
||||||
|
|
||||||
|
# Analyse und Anzeige
|
||||||
|
fig = analyze_paper_breakdown(papier_lengths, papier_voltages, ed_standard_values)
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
papier_ed_real = np.array(papier_voltages) / np.array(papier_lengths)
|
||||||
|
print(f"Gemessene Durchschlagsfeldstärken (ED-Real): {papier_ed_real} kV/mm")
|
||||||
@ -27,7 +27,7 @@ ax1.fill_between(x, u1, u2, color='red', alpha=0.3, label="Abweichung")
|
|||||||
|
|
||||||
# Beschriftungen und Titel für den ersten Subplot setzen
|
# Beschriftungen und Titel für den ersten Subplot setzen
|
||||||
ax1.set_ylabel("Spannung (kV)") # Deutlichere Beschriftung
|
ax1.set_ylabel("Spannung (kV)") # Deutlichere Beschriftung
|
||||||
ax1.set_title("Spannung und Abweichung in Abhängigkeit von der Länge")
|
ax1.set_title("Spannung und Abweichung in Abhängigkeit des Luftspalts")
|
||||||
ax1.legend()
|
ax1.legend()
|
||||||
ax1.grid(True)
|
ax1.grid(True)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user