Skip to content

Commit

Permalink
Add try: except to create legend instead of colorbar (#1028)
Browse files Browse the repository at this point in the history
  • Loading branch information
misi9170 authored Nov 20, 2024
1 parent dff48cd commit 93a9cde
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions floris/wind_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,12 @@ def plot(
)

# Configure the plot
ax.figure.colorbar(sm_ws, ax=ax, **legend_kwargs)
ax.figure.tight_layout()
try:
ax.figure.colorbar(sm_ws, ax=ax, **legend_kwargs)
ax.figure.tight_layout()
except TypeError:
ax.legend(reversed(rects), ws_bins, **legend_kwargs)
ax.figure.get_children()[-1].remove() # Remove the empty colorbar

Check warning on line 787 in floris/wind_data.py

View check run for this annotation

Codecov / codecov/patch

floris/wind_data.py#L782-L787

Added lines #L782 - L787 were not covered by tests
ax.set_theta_direction(-1)
ax.set_theta_offset(np.pi / 2.0)
ax.set_theta_zero_location("N")
Expand Down Expand Up @@ -1822,8 +1826,12 @@ def plot(
)

# Configure the plot
ax.figure.colorbar(sm_wv, ax=ax, **legend_kwargs)
ax.figure.tight_layout()
try:
ax.figure.colorbar(sm_wv, ax=ax, **legend_kwargs)
ax.figure.tight_layout()
except TypeError:
ax.legend(reversed(rects), var_bins, **legend_kwargs)
ax.figure.get_children()[-1].remove() # Remove the empty colorbar

Check warning on line 1834 in floris/wind_data.py

View check run for this annotation

Codecov / codecov/patch

floris/wind_data.py#L1829-L1834

Added lines #L1829 - L1834 were not covered by tests
ax.set_theta_direction(-1)
ax.set_theta_offset(np.pi / 2.0)
ax.set_theta_zero_location("N")
Expand Down

0 comments on commit 93a9cde

Please sign in to comment.