From fa7edd85fa2ef1f0cf4619e4257173a8961618b8 Mon Sep 17 00:00:00 2001 From: abdulwaheedsoudagar Date: Wed, 1 Nov 2023 22:49:23 +0530 Subject: [PATCH] FIX: catplot with redundant hue assignment creates empty legend with title #3537 --- seaborn/categorical.py | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/seaborn/categorical.py b/seaborn/categorical.py index 80c2478d4f..cdb2b3e5ac 100644 --- a/seaborn/categorical.py +++ b/seaborn/categorical.py @@ -409,12 +409,10 @@ def _invert_scale(self, ax, data, vars=("x", "y")): data[col] = inv(data[col]) def _configure_legend(self, ax, func, common_kws=None, semantic_kws=None): - if self.legend == "auto": show_legend = not self._redundant_hue and self.input_format != "wide" else: show_legend = bool(self.legend) - if show_legend: self.add_legend_data(ax, func, common_kws, semantic_kws=semantic_kws) handles, _ = ax.get_legend_handles_labels() @@ -3095,21 +3093,12 @@ def catplot( g._update_legend_data(ax) ax.legend_ = None - if legend and "hue" in p.variables and p.input_format == "long": - # Obtaining the column names for hue, x, and y. - hue_value = p.variables.get("hue") - x_value = p.variables.get("x") - y_value = p.variables.get("y") - # Obtaining the datatype of hue - hue_type = p.var_types.get("hue") - if legend == 'auto' and hue_value in {x_value, y_value} \ - and hue_type != 'numeric': - # Setting the title of hue to None if hue matches "x" or - # "y", or if the data type of "hue" is numeric. - title_hue = None - else: - title_hue = hue_value - g.add_legend(title=title_hue, label_order=hue_order) + if legend == "auto": + show_legend = not p._redundant_hue and p.input_format != "wide" + else: + show_legend = bool(legend) + if show_legend: + g.add_legend(title=p.variables.get("hue"), label_order=hue_order) if data is not None: # Replace the dataframe on the FacetGrid for any subsequent maps