From 1191b615a1f0716215a086d9b4615f1342e92cbe Mon Sep 17 00:00:00 2001 From: Michael Waskom Date: Thu, 16 Jun 2022 06:46:21 -0400 Subject: [PATCH] Minor jointplot user-friendliness (#2863) - Warn/ignore when `ax` is passed as kwarg (closes #2666) - Set the joint axes to be active (closes #2511) --- seaborn/axisgrid.py | 12 ++++++------ tests/test_axisgrid.py | 9 ++++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/seaborn/axisgrid.py b/seaborn/axisgrid.py index 04de7605ad..ae6c9aac87 100644 --- a/seaborn/axisgrid.py +++ b/seaborn/axisgrid.py @@ -2137,12 +2137,9 @@ def jointplot( from .regression import regplot, residplot from .distributions import histplot, kdeplot, _freedman_diaconis_bins - # Handle deprecations - if "size" in kwargs: - height = kwargs.pop("size") - msg = ("The `size` parameter has been renamed to `height`; " - "please update your code.") - warnings.warn(msg, UserWarning) + if kwargs.pop("ax", None) is not None: + msg = "Ignoring `ax`; jointplot is a figure-level function." + warnings.warn(msg, UserWarning, stacklevel=2) # Set up empty default kwarg dicts joint_kws = {} if joint_kws is None else joint_kws.copy() @@ -2285,6 +2282,9 @@ def jointplot( histplot(x=x, hue=hue, ax=grid.ax_marg_x, **marginal_kws) histplot(y=y, hue=hue, ax=grid.ax_marg_y, **marginal_kws) + # Make the main axes active in the matplotlib state machine + plt.sca(grid.ax_joint) + return grid diff --git a/tests/test_axisgrid.py b/tests/test_axisgrid.py index d0ac268907..4a33da94a0 100644 --- a/tests/test_axisgrid.py +++ b/tests/test_axisgrid.py @@ -1788,4 +1788,11 @@ def test_distplot_kwarg_warning(self, long_df): with pytest.warns(UserWarning): g = ag.jointplot(data=long_df, x="x", y="y", marginal_kws=dict(rug=True)) - assert g.ax_marg_x.patches + assert g.ax_marg_x.patches + + def test_ax_warning(self, long_df): + + ax = plt.gca() + with pytest.warns(UserWarning): + g = ag.jointplot(data=long_df, x="x", y="y", ax=ax) + assert g.ax_joint.collections