Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Shorten and explain more calculations in axes_divider. #24461

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

Merged
merged 1 commit into from
Nov 16, 2022

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Nov 15, 2022

Make get_horizontal_sizes, get_vertical_sizes return arrays (which make subsequent computations easier). Move Divider._calc_k, Divider._calc_offsets closer to their use site (i.e. Divider._locate). Inline and shorten offsetbox._determine_karray, offsetbox._calc_offsets into offsetbox._locate which should make the logic easier to follow.

PR Summary

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

Comment on lines 156 to 157
rs_sum, as_sum = sizes.sum(0)
return (total - as_sum) / rs_sum if rs_sum else 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While at it, let's use better names

Suggested change
rs_sum, as_sum = sizes.sum(0)
return (total - as_sum) / rs_sum if rs_sum else 0
rel_sum, abs_sum = sizes.sum(0)
return (total - abs_sum) / rel_sum if rel_sum else 0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, done throughout.

Make get_horizontal_sizes, get_vertical_sizes return arrays (which make
subsequent computations easier).  Move Divider._calc_k,
Divider._calc_offsets closer to their use site (i.e. Divider._locate).
Inline and shorten offsetbox._determine_karray, offsetbox._calc_offsets
into offsetbox._locate which should make the logic easier to follow.
@story645
Copy link
Member

does the code coverage warning need to be resolved?

@jklymak
Copy link
Member

jklymak commented Nov 16, 2022

I would argue it should be, unless we don't care if axes_divider breaks (in which case, why are we optimizing it?)

@QuLogic
Copy link
Member

QuLogic commented Nov 16, 2022

I don't know that this is a true coverage drop; apparently all the GitHub Actions workflows did not upload anything.

@QuLogic QuLogic merged commit 57710db into matplotlib:main Nov 16, 2022
@QuLogic
Copy link
Member

QuLogic commented Nov 16, 2022

And it's all fine now.

@anntzer anntzer deleted the cko branch November 16, 2022 10:30
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.

6 participants