diff --git a/seaborn/_core/plot.py b/seaborn/_core/plot.py index 2723d2a084..d92b6ecb59 100644 --- a/seaborn/_core/plot.py +++ b/seaborn/_core/plot.py @@ -1088,9 +1088,14 @@ def _extract_data(self, p: Plot) -> tuple[PlotData, list[Layer]]: def _resolve_label(self, p: Plot, var: str, auto_label: str | None) -> str: + if re.match(r"[xy]\d+", var): + key = var if var in p._labels else var[0] + else: + key = var + label: str - if var in p._labels: - manual_label = p._labels[var] + if key in p._labels: + manual_label = p._labels[key] if callable(manual_label) and auto_label is not None: label = manual_label(auto_label) else: diff --git a/tests/_core/test_plot.py b/tests/_core/test_plot.py index 91e1008570..f6b5cd0bec 100644 --- a/tests/_core/test_plot.py +++ b/tests/_core/test_plot.py @@ -1751,9 +1751,14 @@ def test_limits(self, long_df): def test_labels(self, long_df): - label = "Z" - p = Plot(long_df, y="y").pair(x=["x", "z"]).label(x1=label).plot() - ax1 = p._figure.axes[1] + label = "zed" + p = ( + Plot(long_df, y="y") + .pair(x=["x", "z"]) + .label(x=str.capitalize, x1=label) + ) + ax0, ax1 = p.plot()._figure.axes + assert ax0.get_xlabel() == "X" assert ax1.get_xlabel() == label