changed Dianas Plot function

This commit is contained in:
Diana 2024-10-23 11:59:29 +02:00
parent 71d8c78f5c
commit 86272cc18a

View File

@ -6,6 +6,7 @@ import matplotlib.pyplot as plt
import numpy as np
import rlxnix as rlx
from useful_functions import power_spectrum
import sys
'''IMPORT DATA'''
datafolder = '../data' #./ wo ich gerade bin; ../ eine ebene höher; ../../ zwei ebenen höher
@ -66,8 +67,12 @@ def power_spectrum_plot(f, p):
ax.set_xlim(0, 1000)
plt.show()
####### ADD DIANAS POWER SPECTRUM PLOT
def plot_highlighted_integrals(frequency, power, exceeding_points, delta, threshold, color_mapping, points_categories):
# DIANAS POWER SPECTRUM PLOT
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
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.
@ -96,16 +101,19 @@ def plot_highlighted_integrals(frequency, power, exceeding_points, delta, thresh
fig, ax = plt.subplots()
ax.plot(frequency, power) # Plot power spectrum
for point in exceeding_points:
integral, local_mean = calculate_integral(frequency, power, point, delta)
valid, _ = valid_integrals(integral, local_mean, threshold, point)
for point in points:
# Use the imported function to calculate the integral and local mean
integral, local_mean, _ = u.calculate_integral(frequency, power, point)
# Use the imported function to check if the point is valid
valid = u.valid_integrals(integral, local_mean, point)
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}")
# Define left and right boundaries of adjacent regions
left_boundary = frequency[np.where((frequency >= point - 5 * delta) & (frequency < point - delta))[0][0]]
@ -114,8 +122,7 @@ def plot_highlighted_integrals(frequency, power, exceeding_points, delta, thresh
# Add vertical dashed lines at the boundaries of the adjacent regions
ax.axvline(x=left_boundary, color="k", linestyle="--")
ax.axvline(x=right_boundary, color="k", linestyle="--")
ax.set_xlim([0, 1200])
ax.set_xlabel('Frequency (Hz)')
ax.set_ylabel('Power')
@ -124,3 +131,4 @@ def plot_highlighted_integrals(frequency, power, exceeding_points, delta, thresh
return fig