Changed dianas plot
This commit is contained in:
parent
51ab5f668b
commit
528823f317
@ -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"
|
functions_path = r"C:\Users\diana\OneDrive - UT Cloud\Master\GPs\GP1_Grewe\Projekt\gpgrewe2024\code"
|
||||||
sys.path.append(functions_path)
|
sys.path.append(functions_path)
|
||||||
import useful_functions as u
|
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):
|
def plot_highlighted_integrals(ax, frequency, power, points, color_mapping, points_categories, delta=2.5):
|
||||||
"""
|
"""
|
||||||
@ -108,23 +113,24 @@ def plot_highlighted_integrals(ax, frequency, power, points, color_mapping, poin
|
|||||||
|
|
||||||
if valid:
|
if valid:
|
||||||
# Define color based on the category of the point
|
# 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')
|
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
|
# 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')
|
ax.axvspan(point - delta, point + delta, color=color, alpha=0.3, label=f'{point_category}')
|
||||||
|
|
||||||
# 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')
|
|
||||||
|
|
||||||
# Print out point, category, and color
|
# Print out point, category, and color
|
||||||
point_category = next((cat for cat, pts in points_categories.items() if point in pts), "Unknown")
|
#ax.text(f"{point_category}: Integral: {integral:.5e}, Color: {color}")
|
||||||
print(f"{point_category}: Integral: {integral:.5e}, Color: {color}")
|
|
||||||
|
|
||||||
ax.set_xlim([0, 1200])
|
ax.set_xlim([0, 1200])
|
||||||
|
ax.set_ylim([0, 6e-5])
|
||||||
ax.set_xlabel('Frequency (Hz)')
|
ax.set_xlabel('Frequency (Hz)')
|
||||||
ax.set_ylabel('Power')
|
ax.set_ylabel('Power')
|
||||||
ax.set_title('Power Spectrum with Highlighted Integrals')
|
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))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user