From 32c5fa9d9894741a159fbc61eea01e19c76797f8 Mon Sep 17 00:00:00 2001 From: FloraSauerbronn Date: Tue, 23 Jul 2024 11:05:11 -0300 Subject: [PATCH] fix ruff tests --- gliderpy/plotting.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/gliderpy/plotting.py b/gliderpy/plotting.py index b175924..6a7eb0f 100644 --- a/gliderpy/plotting.py +++ b/gliderpy/plotting.py @@ -95,38 +95,39 @@ def plot_transect( @register_dataframe_method def plot_ctd( df: pd.DataFrame, - idx: int, + profile_number: int, var: str, ax: plt.Axes = None, - color: str = None + color: str | None = None, ) -> tuple: """Make a CTD profile plot of pressure vs property depending on what variable was chosen. - :param idx: index of position + + :param profile_number: profile number of CTD :param var: variable to plot against pressure :param ax: existing axis to plot on (default: None) :param color: color for the plot line (default: None) :return: figure, axes """ g = df.groupby(["longitude", "latitude"]) - profile = g.get_group((list(g.groups)[idx])) + profile = g.get_group(list(g.groups)[profile_number]) if ax is None: fig, ax1 = plt.subplots(figsize=(5, 6)) ax1.plot(profile[var], -profile["pressure"], label=var, color=color) - ax1.set_ylabel('Pressure') + ax1.set_ylabel("Pressure") ax1.set_xlabel(var) ax1.legend() return fig, ax1 - else: - fig = ax.get_figure() - ax2 = ax.twiny() # Create a new twinned axis - ax2.plot(profile[var], -profile["pressure"], label=var, color=color) - ax2.set_xlabel(var) - - # Handle legends - lines, labels = ax.get_legend_handles_labels() - lines2, labels2 = ax2.get_legend_handles_labels() - ax.legend(lines + lines2, labels + labels2, loc="lower center") - - return fig, ax2 + + fig = ax.get_figure() + ax2 = ax.twiny() # Create a new twinned axis + ax2.plot(profile[var], -profile["pressure"], label=var, color=color) + ax2.set_xlabel(var) + + # Handle legends + lines, labels = ax.get_legend_handles_labels() + lines2, labels2 = ax2.get_legend_handles_labels() + ax.legend(lines + lines2, labels + labels2, loc="lower center") + + return fig, ax2