Skip to content

Conversation

mwaskom
Copy link
Owner

@mwaskom mwaskom commented Aug 1, 2022

This PR adds a Plot.theme method for controlling the appearance of data-independent plot elements, using matplotlib rc parameters.

This is a provisional approach for the initial release and will be improved over time.

Currently, Plot.theme accepts one positional-only argument, which should be a dictionary of rc parameters. To use "seaborn themes", you can call the relevant functions in the seaborn namespace (sns):

(
    so.Plot(diamonds, "clarity")
    .add(so.Bar(), so.Hist())
    .theme({**sns.axes_style("whitegrid"), "patch.linewidth": 3})
)

image

This is a little clunky; I do expect that it will become possible to use "named' themes more directly, but I am not sure what that interface should look like yet.

This also makes the default theme independent of other matplotlib rc manipulations, including ones performed by seaborn.set_* functions. The default theme does match what you'd get when you call sns.set_theme() with no arguments. There was an attempt to distinguish between "stylistic" rcparams and "logical" params and continue to let matplotlib respect the latter, but the exact set may change in the future.

Currently there is no way to change the default for all plots. I expect that will be added later, I am thinking something along the lines of

so.Plot.default.theme = {...}

rather than functions that magically change global state, as currently works with matplotlib.

Why is this feature in a partially-finished state? There are some tricky API decisions here and I am not ready to commit to more complex implementation, do not want to block the initial release, and do want to provide some capacity for customization.

@mwaskom mwaskom added this to the v0.12.0 milestone Aug 1, 2022
@codecov
Copy link

codecov bot commented Aug 2, 2022

Codecov Report

Merging #2929 (a982059) into master (949dec3) will increase coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2929      +/-   ##
==========================================
+ Coverage   98.24%   98.29%   +0.05%     
==========================================
  Files          69       69              
  Lines       22898    22950      +52     
==========================================
+ Hits        22496    22559      +63     
+ Misses        402      391      -11     
Impacted Files Coverage Δ
seaborn/_core/plot.py 97.29% <100.00%> (+1.76%) ⬆️
tests/_core/test_plot.py 98.54% <100.00%> (+0.02%) ⬆️
tests/_marks/test_lines.py 100.00% <100.00%> (ø)

@mwaskom mwaskom merged commit 762db89 into master Aug 4, 2022
@mwaskom mwaskom deleted the plot/theme branch August 4, 2022 00:52
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