Skip to content

Commit

Permalink
Minor jointplot user-friendliness (#2863)
Browse files Browse the repository at this point in the history
- Warn/ignore when `ax` is passed as kwarg (closes #2666)
- Set the joint axes to be active (closes #2511)
  • Loading branch information
mwaskom authored Jun 16, 2022
1 parent b56081c commit 1191b61
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
12 changes: 6 additions & 6 deletions seaborn/axisgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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


Expand Down
9 changes: 8 additions & 1 deletion tests/test_axisgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1191b61

Please sign in to comment.