diff --git a/code/plot_functions.py b/code/plot_functions.py index 63be604..1f84e19 100644 --- a/code/plot_functions.py +++ b/code/plot_functions.py @@ -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 +