Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add apply and pipe methods to Grid objects for fluent customization #2928

Merged
merged 4 commits into from
Jul 31, 2022

Conversation

mwaskom
Copy link
Owner

@mwaskom mwaskom commented Jul 30, 2022

These two methods accept an function that operates on a Grid object to do additional customization of the plot. The methods are very similar, but apply returns the Grid it is attached to while pipe returns the value from the passed function. The objective is to make it easier to do arbitrary customization without catching the return value and switching to an imperative programming style.

Example:

def slopeline(grid, slope, **kwargs):
    grid.ax.axline((0, 0), slope=slope, **kwargs)

(
    sns.relplot(tips, x="total_bill", y="tip")
    .apply(slopeline, slope=.2, color=".6")
    .set_axis_labels("Total bill", "Tip")
)

image

Additionally, fixed two methods (tight_layout and refline) that were not returning self.

@mwaskom mwaskom added this to the v0.12.0 milestone Jul 30, 2022
@mwaskom mwaskom changed the title Add apply and pipe methods to FacetGrid for fluent customization Add apply and pipe methods to Grid objects for fluent customization Jul 30, 2022
@codecov
Copy link

codecov bot commented Jul 30, 2022

Codecov Report

Merging #2928 (8b78045) into master (f581300) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2928   +/-   ##
=======================================
  Coverage   98.24%   98.24%           
=======================================
  Files          69       69           
  Lines       22866    22890   +24     
=======================================
+ Hits        22464    22488   +24     
  Misses        402      402           
Impacted Files Coverage Δ
seaborn/axisgrid.py 97.18% <100.00%> (+0.01%) ⬆️
tests/test_axisgrid.py 99.37% <100.00%> (+<0.01%) ⬆️

seaborn/axisgrid.py Outdated Show resolved Hide resolved
seaborn/axisgrid.py Outdated Show resolved Hide resolved
@mwaskom mwaskom merged commit 949dec3 into master Jul 31, 2022
@mwaskom mwaskom deleted the facet/piping branch July 31, 2022 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant