Skip to content

Commit

Permalink
fix ruff tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FloraSauerbronn committed Jul 23, 2024
1 parent 1e7eb20 commit 32c5fa9
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions gliderpy/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 32c5fa9

Please sign in to comment.