FIX: make EngFormatter respect axes.formatter.use_locale rcParam - #32281
FIX: make EngFormatter respect axes.formatter.use_locale rcParam#32281christianaurichzm wants to merge 1 commit into
Conversation
|
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. |
EngFormatter subclasses ScalarFormatter, but the inherited locale machinery is reachable only in the offset path. The normal engineering formatting path both forces the flag off at construction, by passing useLocale=False to super().__init__, and bypasses locale-aware formatting, by interpolating the mantissa directly. The rcParam therefore had no effect, and set_useLocale flipped a flag that format_data never consulted. Pass useLocale through to ScalarFormatter and add the matching keyword argument, so that the rcParam applies and an explicit value overrides it. When locale formatting is on, the mantissa goes through locale.format_string, and the separators it introduces are escaped for mathtext the same way ScalarFormatter already escapes them.
2285392 to
3694152
Compare
Description
EngFormatterignoresaxes.formatter.use_localewhen formatting the mantissa.With
de_DE.UTF-8:There are two causes:
EngFormatter.__init__passesuseLocale=FalsetoScalarFormatter, andformat_dataformats the mantissa directly instead of using locale-aware formatting. Because of the latter, evenset_useLocale(True)does not affect the normalformat_datapath. Locale-aware formatting is currently only used for the offset path.This change passes
useLocalethrough toScalarFormatter, adds it as anEngFormatterkeyword argument, and applies locale formatting to the mantissa. For MathText, locale separators are escaped to avoid punctuation spacing.Tests cover the rcParam, explicit
useLocalevalues, the inherited setter, and MathText.I consider this a bug fix:
EngFormatteralready inherits the locale API fromScalarFormatter, but does not honor it consistently. #13477 fixed the same kind of issue foraxes.unicode_minus.The new constructor keyword is the only public API addition here and can be split out if preferred.
Related: #25006 concerns the same rcParam, but a different issue involving locale initialization/reset behavior.
PR quality check