Changes integral function
This commit is contained in:
parent
3a1d7748ba
commit
423fe451be
@ -72,14 +72,16 @@ functions_path = r"C:\Users\diana\OneDrive - UT Cloud\Master\GPs\GP1_Grewe\Proje
|
||||
sys.path.append(functions_path)
|
||||
import useful_functions as u
|
||||
import matplotlib.ticker as ticker
|
||||
import matplotlib.patches as mpatches
|
||||
|
||||
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):
|
||||
"""
|
||||
Highlight integrals on the existing axes of the power spectrum.
|
||||
Highlights integrals on the existing axes of the power spectrum for a given dataset.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
@ -102,38 +104,40 @@ def plot_highlighted_integrals(ax, frequency, power, points, color_mapping, poin
|
||||
-------
|
||||
None
|
||||
"""
|
||||
ax.plot(frequency, power, color = "k") # Plot power spectrum on the existing axes
|
||||
_, _, AM, df, eodf, nyquist, stim_freq = u.sam_data(sam)
|
||||
|
||||
# Plot the power spectrum on the provided axes
|
||||
ax.plot(frequency, power, color="k")
|
||||
|
||||
for point in points:
|
||||
# Calculate the integral and local mean
|
||||
integral, local_mean = u.calculate_integral_2(frequency, power, point)
|
||||
# Identify the category for the current point
|
||||
point_category = next((cat for cat, pts in points_categories.items() if point in pts), "Unknown")
|
||||
|
||||
# Check if the point is valid
|
||||
# Assign color based on category, or default to grey if unknown
|
||||
color = color_mapping.get(point_category, 'gray')
|
||||
|
||||
# Calculate the integral and check validity
|
||||
integral, local_mean = u.calculate_integral_2(frequency, power, point)
|
||||
valid = u.valid_integrals(integral, local_mean, point)
|
||||
|
||||
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
|
||||
if valid:
|
||||
# Highlight valid points with a shaded region
|
||||
ax.axvspan(point - delta, point + delta, color=color, alpha=0.2, label=f'{point_category}')
|
||||
|
||||
# Text with categories and colors
|
||||
ax.text(1000, 5.8e-5, "AM", fontsize=10, color="green", alpha=0.2)
|
||||
ax.text(1000, 5.6e-5, "Nyquist", fontsize=10, color="blue", alpha=0.2)
|
||||
ax.text(1000, 5.4e-5, "EODf", fontsize=10, color="red", alpha=0.2)
|
||||
ax.text(1000, 5.2e-5, "Stimulus frequency", fontsize=10, color="orange", alpha=0.2)
|
||||
ax.text(1000, 5.0e-5, "EODf of awake fish", fontsize=10, color="purple", alpha=0.2)
|
||||
|
||||
# Set plot limits and labels
|
||||
ax.set_xlim([0, 1200])
|
||||
ax.set_ylim([0, 6e-5])
|
||||
ax.axvline(nyquist, color = "k", linestyle = "--")
|
||||
ax.set_xlabel('Frequency (Hz)')
|
||||
ax.set_ylabel('Power')
|
||||
ax.set_title('Power Spectrum with highlighted Integrals')
|
||||
ax.set_title('Power Spectrum with Highlighted Integrals')
|
||||
|
||||
# Apply float formatting to the y-axis
|
||||
ax.yaxis.set_major_formatter(ticker.FuncFormatter(float_formatter))
|
||||
ax.legend(loc="upper right")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user