Changed dianas plot

This commit is contained in:
Diana 2024-10-24 17:02:14 +02:00
parent 51ab5f668b
commit 528823f317

View File

@ -71,6 +71,11 @@ def power_spectrum_plot(f, p):
functions_path = r"C:\Users\diana\OneDrive - UT Cloud\Master\GPs\GP1_Grewe\Projekt\gpgrewe2024\code"
sys.path.append(functions_path)
import useful_functions as u
import matplotlib.ticker as ticker
def float_formatter(x, _):
"""Format the y-axis values as floats with a specified precision."""
return f'{x:.5f}'
def plot_highlighted_integrals(ax, frequency, power, points, color_mapping, points_categories, delta=2.5):
"""
@ -98,7 +103,7 @@ def plot_highlighted_integrals(ax, frequency, power, points, color_mapping, poin
None
"""
ax.plot(frequency, power) # Plot power spectrum on the existing axes
for point in points:
# Calculate the integral and local mean
integral, local_mean = u.calculate_integral_2(frequency, power, point)
@ -108,23 +113,24 @@ def plot_highlighted_integrals(ax, frequency, power, points, color_mapping, poin
if valid:
# Define color based on the category of the point
point_category = next((cat for cat, pts in points_categories.items() if point in pts), "Unknown")
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')
# 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')
ax.axvspan(point - delta, point + delta, color=color, alpha=0.3, label=f'{point_category}')
# Print out point, category, and color
point_category = next((cat for cat, pts in points_categories.items() if point in pts), "Unknown")
print(f"{point_category}: Integral: {integral:.5e}, Color: {color}")
#ax.text(f"{point_category}: Integral: {integral:.5e}, Color: {color}")
ax.set_xlim([0, 1200])
ax.set_ylim([0, 6e-5])
ax.set_xlabel('Frequency (Hz)')
ax.set_ylabel('Power')
ax.set_title('Power Spectrum with Highlighted Integrals')
#ax.legend()
# Apply float formatting to the y-axis
ax.yaxis.set_major_formatter(ticker.FuncFormatter(float_formatter))