From 93a9cde65c1d3b950e0975b4025530d735b36951 Mon Sep 17 00:00:00 2001 From: misi9170 <39596329+misi9170@users.noreply.github.com> Date: Wed, 20 Nov 2024 12:27:54 -0500 Subject: [PATCH] Add try: except to create legend instead of colorbar (#1028) --- floris/wind_data.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/floris/wind_data.py b/floris/wind_data.py index b470fe515..3d49dec4b 100644 --- a/floris/wind_data.py +++ b/floris/wind_data.py @@ -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 ax.set_theta_direction(-1) ax.set_theta_offset(np.pi / 2.0) ax.set_theta_zero_location("N") @@ -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 ax.set_theta_direction(-1) ax.set_theta_offset(np.pi / 2.0) ax.set_theta_zero_location("N")