34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
import matplotlib.pyplot as plt
|
|
import numpy as np
|
|
from scipy.interpolate import make_interp_spline
|
|
|
|
abstand = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
|
|
messwerte = np.array([65.01, 40.41, 26.67, 19.65, 15.61, 13.13, 11.11, 10.08, 8.85, 7.93])
|
|
|
|
konstante = messwerte[0] * abstand[0]
|
|
idealwerte = konstante / abstand
|
|
|
|
# Spline-Interpolation für Messwerte
|
|
xnew = np.linspace(abstand.min(), abstand.max(), 300)
|
|
spl = make_interp_spline(abstand, messwerte, k=3)
|
|
messwerte_smooth = spl(xnew)
|
|
|
|
# Spline-Interpolation für Idealwerte
|
|
spl_ideal = make_interp_spline(abstand, idealwerte, k=3)
|
|
idealwerte_smooth = spl_ideal(xnew)
|
|
|
|
plt.figure(figsize=(10, 6))
|
|
|
|
# Fläche zwischen den Graphen füllen
|
|
plt.fill_between(xnew, messwerte_smooth, idealwerte_smooth, color='red', alpha=0.3, label='Differenz') # alpha für Transparenz
|
|
|
|
plt.plot(xnew, messwerte_smooth, linestyle='-', label='Messwerte (geglättet)')
|
|
plt.plot(xnew, idealwerte_smooth, linestyle='--', label='Idealwerte (geglättet)')
|
|
plt.xlabel('Abstand l [mm]')
|
|
plt.ylabel('Kapazität C [pF]')
|
|
#plt.title('Kapazität in Korrelation zum Abstand eines Luftkondensators (geglättet)')
|
|
plt.grid(True)
|
|
plt.legend()
|
|
plt.xticks(abstand)
|
|
plt.yticks(np.arange(min(messwerte), max(messwerte)+5, 5.0))
|
|
plt.show() |