From 861a689f4e631eca9840c59d047528864fa0ec0d Mon Sep 17 00:00:00 2001 From: Diana Date: Mon, 28 Oct 2024 15:19:37 +0100 Subject: [PATCH] Changes dianas plot --- code/plot_functions.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/code/plot_functions.py b/code/plot_functions.py index f9708d8..4850e1e 100644 --- a/code/plot_functions.py +++ b/code/plot_functions.py @@ -73,12 +73,12 @@ sys.path.append(functions_path) import useful_functions as u import matplotlib.ticker as ticker import matplotlib.patches as mpatches +import matplotlib.cm as cm 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, nyquist, true_eodf, color_mapping, points_categories, delta=2.5): """ Highlights integrals on the existing axes of the power spectrum for a given dataset. @@ -104,8 +104,17 @@ def plot_highlighted_integrals(ax, frequency, power, points, nyquist, true_eodf, ------- None """ + # Define color mappings for specific categories + category_colors = { + "AM": "#ff7f0e", + "Nyquist": "#2ca02c", + "EODf": "#d62728", + "Stimulus": "#9467bd", + "EODf (awake fish)": "#8c564b" + } + # Plot the power spectrum on the provided axes - ax.plot(frequency, power, color="k") + for point in points: # Identify the category for the current point @@ -120,20 +129,24 @@ def plot_highlighted_integrals(ax, frequency, power, points, nyquist, true_eodf, if valid: # Highlight valid points with a shaded region - ax.axvspan(point - delta, point + delta, color=color, alpha=0.2, label=f'{point_category}') + ax.axvspan(point - delta, point + delta, color=color, alpha=0.35, label=f'{point_category}') + + ax.plot(frequency, power) + # Use the category colors for 'Nyquist' and 'EODf' lines + ax.axvline(nyquist, color=category_colors.get("Nyquist", "#2ca02c"), linestyle="--") + ax.axvline(true_eodf, color=category_colors.get("EODf (awake fish)", "#8c564b"), linestyle="--") # Set plot limits and labels ax.set_xlim([0, 1200]) ax.set_ylim([0, 6e-5]) - ax.axvline(nyquist, color = "k", linestyle = "--") - ax.axvline(true_eodf, color = "k", linestyle = "--") - ax.set_xlabel('Frequency (Hz)') - ax.set_ylabel('Power') - ax.set_title('Power Spectrum with Highlighted Integrals') + ax.set_xlabel('Frequency (Hz)', fontsize=12) + ax.set_ylabel(r'Power [$\frac{\mathrm{mV^2}}{\mathrm{Hz}}$]', fontsize=12) + #ax.set_title('Power Spectrum with highlighted Integrals', fontsize=14) # Apply float formatting to the y-axis ax.yaxis.set_major_formatter(ticker.FuncFormatter(float_formatter)) - #ax.legend(loc="upper right") + +