Don't require an axis in PercentFormatter with explicit decimals#31995
Don't require an axis in PercentFormatter with explicit decimals#31995Sreekant13 wants to merge 1 commit into
Conversation
PercentFormatter.__call__ always read self.axis.get_view_interval(), but that display range is only used to choose the number of decimals automatically, i.e. when decimals is None. With decimals set explicitly, calling the formatter while it was not attached to an axis raised AttributeError even though the axis value was never needed. Only read the axis in the auto-decimals case, and add a regression test.
|
Thank you for opening your first PR into Matplotlib! If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process. You can also join us on discourse chat for real-time discussion. For details on testing, writing docs, and our review process, please see the developer guide. We strive to be a welcoming and open project. Please follow our Code of Conduct. |
dstansby
left a comment
There was a problem hiding this comment.
Seems like a reasonable improvement - thanks for the PR
PR summary
PercentFormatter.__call__always readsself.axis.get_view_interval(), but that display range is only used to choose the number of decimals automatically, i.e. whendecimals is None. Withdecimalsset explicitly, calling the formatter while it is not attached to an axis raisedAttributeError, even though the axis value is never needed.PercentFormattercreated with explicitdecimalsalready has everything it needs to format a value, but it still required an axis, so using it standalone (for example to build a label or annotation) crashed.format_pct, so__call__now reads it only whendecimals is None. Auto-decimals still requires an axis, unchanged.Minimal self-contained example:
PR checklist
TestPercentFormatter.test_call_without_axis; existingformat_pctcases are unchanged and still pass