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

Allow Plot.label to control title(s) #2934

Merged
merged 8 commits into from
Aug 4, 2022
Merged

Allow Plot.label to control title(s) #2934

merged 8 commits into from
Aug 4, 2022

Conversation

mwaskom
Copy link
Owner

@mwaskom mwaskom commented Aug 2, 2022

Following on #2919 to support titles. It expands the API in a few ways:

  1. The title= parameter allows setting directly a title for a single-axes plot
so.Plot().label(title="Here is a plot")

image

  1. The title= parameter also can be passed a function that operates on the auto-titles in a faceting context
so.Plot().facet(["a", "b"]).label(title=str.capitalize)

image

  1. The col= or row= parameters accept a string that adds a prefix to facet titles:
so.Plot().facet(["a", "b"], ["x", "y"]).label(col="Column", row="Row")

image

Note two relevant changes from the way titles work in FacetGrid:

  • A label for the variable name is not added by default
  • The order of the titles is {col} | {row}, corresponding to the change in the order of positional arguments (column faceting is more useful than row faceting so it should be prioritized)

I would like to add, and probably default to "margin titles" for the row variable, but that isn't implemented yet.

The combination of the faceting variables is not currently customizable with a template akin to what FacetGrid.set_titles accepts, but you can customize a single dimension:

so.Plot().facet([1, 2]).label(title="{}st column".format)

image

I see some potential for title vs col/row to be a little confusing so may revisit this during the experimental phase.

"Suptitles" and captions are likely in scope for this method too, but I don't want to commit to them yet because the interaction with matplotlib autolayouts is trickier.

@codecov
Copy link

codecov bot commented Aug 2, 2022

Codecov Report

Merging #2934 (1562c2f) into master (762db89) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2934   +/-   ##
=======================================
  Coverage   98.30%   98.30%           
=======================================
  Files          69       69           
  Lines       22954    22985   +31     
=======================================
+ Hits        22565    22596   +31     
  Misses        389      389           
Impacted Files Coverage Δ
seaborn/_core/plot.py 97.33% <100.00%> (+0.03%) ⬆️
tests/_core/test_plot.py 98.56% <100.00%> (+0.02%) ⬆️

@mwaskom mwaskom added this to the v0.12.0 milestone Aug 3, 2022
@mwaskom mwaskom merged commit a259ac5 into master Aug 4, 2022
@mwaskom mwaskom deleted the plot/titles branch August 4, 2022 02:41
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