changed plotting for integrals

This commit is contained in:
Diana 2024-10-23 15:35:47 +02:00
parent 0a3a8c59af
commit 9ea4e23bae

View File

@ -72,7 +72,7 @@ functions_path = r"C:\Users\diana\OneDrive - UT Cloud\Master\GPs\GP1_Grewe\Proje
sys.path.append(functions_path)
import useful_functions as u
def plot_highlighted_integrals(frequency, power, points, color_mapping, points_categories, delta = 2.5):
def plot_highlighted_integrals(frequency, power, points, color_mapping, points_categories, delta=2.5):
"""
Plot the power spectrum and highlight integrals that exceed the threshold.
@ -82,12 +82,10 @@ def plot_highlighted_integrals(frequency, power, points, color_mapping, points_c
An array of frequencies corresponding to the power values.
power : np.array
An array of power spectral density values.
exceeding_points : list
A list of harmonic frequencies that exceed the threshold.
points : list
A list of harmonic frequencies to check and highlight.
delta : float
Half-width of the range for integration around each point.
threshold : float
Threshold value to compare integrals with local mean.
color_mapping : dict
A dictionary mapping each category to its color.
points_categories : dict
@ -111,10 +109,16 @@ def plot_highlighted_integrals(frequency, power, points, color_mapping, points_c
if valid:
# Define color based on the category of the point
color = next((c for cat, c in color_mapping.items() if point in points_categories[cat]), 'gray')
# Shade the region around the point where the integral was calculated
ax.axvspan(point - delta, point + delta, color=color, alpha=0.3, label=f'{point:.2f} Hz')
print(f"Integral around {point:.2f} Hz: {integral:.5e}")
# Print out point and color
print(f"Integral around {point:.2f} Hz: {integral:.5e}, Color: {color}")
# Annotate the plot with the point and its color
ax.text(point, max(power) * 0.9, f'{point:.2f}', color=color, fontsize=10, ha='center')
# Define left and right boundaries of adjacent regions
left_boundary = frequency[np.where((frequency >= point - 5 * delta) & (frequency < point - delta))[0][0]]
right_boundary = frequency[np.where((frequency > point + delta) & (frequency <= point + 5 * delta))[0][-1]]
@ -132,3 +136,4 @@ def plot_highlighted_integrals(frequency, power, points, color_mapping, points_c
return fig