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

Mask nonpositive values with log_scale and ignore inf data in histogram range #3488

Merged
merged 1 commit into from
Sep 23, 2023

Conversation

mwaskom
Copy link
Owner

@mwaskom mwaskom commented Sep 23, 2023

Two related updates in one PR:

When handling the log_scale option by setting a matplotlib axes scale, use nonpositive="mask" so that nonpositive values are dropped rather than set to an arbitrarily small value. This avoids surprises where the small value is aggregated, which are actively wrong.

A consequence is that bar plots on a log value scale no longer magically "work" and require the user to explicitly set a bottom value. This is unfortunately but IMO a reasonable tradeoff; bar plots on a log value scale are sort of an anti-pattern anyway IMO and this does require one to be thoughtful about what that means and where the bar should start. Ultimately one is going to be surprised either way and I lean towards the plot being surprisingly empty over the plot having surprisingly wrong values.

A downstream but technically independent update here is that histogram computation now ignores infinite values when computing the default range. This is another behavior where you could argue multiple sides (previously it raised an exception) but silently ignoring infinite values is more consistent with what happens elsewhere in matplotlib and seaborn.

@codecov
Copy link

codecov bot commented Sep 23, 2023

Codecov Report

Merging #3488 (50d6360) into master (4c90fa9) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3488   +/-   ##
=======================================
  Coverage   98.33%   98.33%           
=======================================
  Files          75       75           
  Lines       24565    24570    +5     
=======================================
+ Hits        24157    24162    +5     
  Misses        408      408           
Files Changed Coverage Δ
seaborn/_base.py 97.37% <100.00%> (ø)
seaborn/_stats/counting.py 100.00% <100.00%> (ø)
tests/test_distributions.py 99.80% <100.00%> (+<0.01%) ⬆️

@mwaskom mwaskom merged commit c01e103 into master Sep 23, 2023
12 checks passed
@mwaskom mwaskom deleted the enh/log_scale_nonpositive branch September 23, 2023 22:59
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