Skip to content

Commit

Permalink
Also allow Plot.label to control all paired axes (#3459)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwaskom authored Sep 1, 2023
1 parent 74a8301 commit ff446ee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
9 changes: 7 additions & 2 deletions seaborn/_core/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions tests/_core/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit ff446ee

Please sign in to comment.