Skip to content

Commit

Permalink
Move apply/pipe down to base class so JointGrid/PaiGrid get them too
Browse files Browse the repository at this point in the history
  • Loading branch information
mwaskom committed Jul 30, 2022
1 parent 3ec5f62 commit 500d2fb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion doc/whatsnew/v0.12.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Other updates

- |Feature| It is now possible to aggregate / sort a :func:`lineplot` along the y axis using `orient="y"` (:pr:`2854`).

- |Feature| Made it easier to customize :class:`FacetGrid` with a fluent (method-chained) style by adding :meth:`FacetGrid.apply` / :meth:`FacetGrid.pipe` and fixing :meth:`FacetGrid.tight_layout` / :meth:`FacetGrid.refline` so that they return `self` (:pr:`2926`).
- |Feature| Made it easier to customize :class:`FacetGrid` / :class:`PairGrid` / :class:`JointGrid` with a fluent (method-chained) style by adding `apply`/ `pipe` methods. Additionally, fixed the `tight_layout` and `refline` methods so that they return `self` (:pr:`2926`).

- |Enhancement| Added a `width` parameter to :func:`barplot` (:pr:`2860`).

Expand Down
58 changes: 29 additions & 29 deletions seaborn/axisgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,35 @@ def figure(self):
"""Access the :class:`matplotlib.figure.Figure` object underlying the grid."""
return self._figure

def apply(self, func, *args, **kwargs):
"""
Customize the grid with a user-supplied function and return self.
The `func` must accept an object of this type for its first
positional argument. Additional arguments are passed through.
The return value of `func` is ignored; this method returns self.
See the `pipe` method if you want the return value.
Added in v0.12.0.
"""
func(self, *args, **kwargs)
return self

def pipe(self, func, *args, **kwargs):
"""
Customize the grid with a user-supplied function and return its value.
The `func` must accept an object of this type for its first
positional argument. Additional arguments are passed through.
The return value of `func` becomes the return value of this method.
See the `apply` method if you want to return self instead.
Added in v0.12.0.
"""
return func(self, *args, **kwargs)

def savefig(self, *args, **kwargs):
"""
Save an image of the plot.
Expand Down Expand Up @@ -775,35 +804,6 @@ def map_dataframe(self, func, *args, **kwargs):

return self

def apply(self, func, *args, **kwargs):
"""
Customize the grid with a user-supplied function and return self.
The `func` must accept a :class:`FacetGrid` object for its first
positional argument. Additional arguments are passed through.
The return value of `func` is ignored; this method returns self.
See :meth:`FacetGrid.pipe` if you want the return value.
Added in v0.12.0.
"""
func(self, *args, **kwargs)
return self

def pipe(self, func, *args, **kwargs):
"""
Customize the grid with a user-supplied function and return its value.
The `func` must accept a :class:`FacetGrid` object for its first
positional argument. Additional arguments are passed through.
The return value of `func` becomes the return value of this method.
See :meth:`FacetGrid.apply` if you want to return self instead.
Added in v0.12.0.
"""
return func(self, *args, **kwargs)

def _facet_color(self, hue_index, kw_color):

color = self._colors[hue_index]
Expand Down

0 comments on commit 500d2fb

Please sign in to comment.