Skip to content

Commit

Permalink
Fixing ax in plot_ctd and creating new baseline image
Browse files Browse the repository at this point in the history
  • Loading branch information
FloraSauerbronn committed Jul 29, 2024
1 parent 9232e5c commit 5240abb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions gliderpy/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,17 @@ def plot_ctd(
return fig, ax1

fig = ax.get_figure()
ax2 = ax.twiny() # Create a new twinned axis

# Check if the ax is already a twinx or twiny
if hasattr(ax, "twinned_axis"):
ax2 = ax.twinned_axis
else:
ax2 = ax.twiny()
ax.twinned_axis = ax2 # Keep a reference to the 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")
Expand Down
Binary file modified tests/baseline/test_plot_ctd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ def test_plot_transect_size(glider_data):
@pytest.mark.mpl_image_compare(baseline_dir=root.joinpath("baseline/"))
def test_plot_ctd(glider_data):
"""Test plot_ctd accessor."""
fig, ax = plot_ctd(glider_data, 0, var="temperature")
fig, ax = plot_ctd(glider_data, 0, var="temperature", color="blue")
return fig

0 comments on commit 5240abb

Please sign in to comment.