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 Boolean scale #3205

Merged
merged 9 commits into from
Dec 30, 2022
Merged

Add Boolean scale #3205

merged 9 commits into from
Dec 30, 2022

Conversation

mwaskom
Copy link
Owner

@mwaskom mwaskom commented Dec 29, 2022

This PR adds a new Scale object, Boolean, that has a domain of True and False.

There's a bit of a tension with boolean data: True/False can be (and often are) cast to 0/1 and treated numerically, but (even when using True and False as labels) it feels odd to sort them such that axes or legends read "False, True". Therefore, this scale aims to maintain a True, False ordering.

The scale is used by default for data with dtype bool, "boolean" (pandas' na-aware dtype), or object types (including bare Python lists) with only True/False values:

(
    so.Plot(titanic, "adult_male", "age", color="survived")
    .add(so.Dots(), so.Jitter())
)

It can also be assigned manually, which will also cast the input values to booleans:

(
    so.Plot(titanic, "adult_male", "age", color="survived")
    .add(so.Dots(), so.Jitter())
    .scale(color=so.Boolean())
)

There aren't currently many options; maybe it makes sense to add some, but for now it just accepts a single values parameter which is relevant for semantic properties (e.g., it can be a list of colors, or a palette name, or a range of point sizes, etc.).

@codecov
Copy link

codecov bot commented Dec 29, 2022

Codecov Report

Merging #3205 (8ad5fed) into master (7271035) will increase coverage by 0.00%.
The diff coverage is 98.79%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           master    #3205    +/-   ##
========================================
  Coverage   98.42%   98.42%            
========================================
  Files          77       77            
  Lines       24179    24405   +226     
========================================
+ Hits        23798    24021   +223     
- Misses        381      384     +3     
Impacted Files Coverage Δ
seaborn/_core/scales.py 90.65% <94.93%> (+0.56%) ⬆️
seaborn/_core/plot.py 99.33% <100.00%> (-0.01%) ⬇️
seaborn/_core/properties.py 99.52% <100.00%> (+0.33%) ⬆️
seaborn/_core/rules.py 100.00% <100.00%> (ø)
seaborn/objects.py 100.00% <100.00%> (ø)
tests/_core/test_properties.py 98.91% <100.00%> (-0.01%) ⬇️
tests/_core/test_rules.py 100.00% <100.00%> (ø)
tests/_core/test_scales.py 100.00% <100.00%> (ø)

@mwaskom mwaskom merged commit 5e565d2 into master Dec 30, 2022
@mwaskom mwaskom deleted the scale/boolean branch December 30, 2022 16:07
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.

None yet

1 participant