-
Notifications
You must be signed in to change notification settings - Fork 0
Matplotlib tick units should be localised according to country and language #11
Comments
The code for the Matplotlib Engineering ticker is here: https://github.com/matplotlib/matplotlib/blob/v3.5.1/lib/matplotlib/ticker.py#L1311-L1459 It may be do-able to create a modified class with a 'locale' function to implement localised formatted units using Babel... |
Perhaps it could be done by mapping between the units used by the Eng ticker, and those present in the CLDR Unit Validity XML file which Babel uses (according to the format_unit() specification, linked above). |
Matplotlib Eng ticker seems to essentially be used to scale according to SI metric prefixes representing power to base 10 (from -24 to 24), while Babel is focused on a broader set of units but not necessarily with coverage of all of these powers. Pint, another python library for dealing with units has created a plain language look up of these for the xml-derived terms here) -- and notably there doesn't seem to be a way of dealing with, for example 'septillionth/quadrillionth', being 'y' or 10−24. At least, in a naive test, Babel doesn't recognise those words as being English (not suprising, they aren't in the xml spec):
Just entering 'y' doesn't work either -- Babel appears to use a kind of search to find the closest matching unit, and for 'y' it picks 'days'. I think this must be done because the formal term for km is 'length-kilometer' but it matches correctly if you say 'kilometer' (but not kilometre). Anyway - the short story is
But come to think of it, I'm not sure that Babel has support for 'thousands'.... I think i missed that in considering the above |
Currently, tick marks for the threshold plots are handled by matplotlib's engineering ticker
For numbers in the thousands this has the result of abbreviating units using a 'k' which is generally desirable, at least in English.
However, in Czech the meaning of 'k' is not natural/intuitive; for example, a better option would be "tisíce" (thousand).
There is a python library for localising units which we have implemented elsewhere in the code for this project, Babel, which has a format_unit() function that could potentially be used for this. However, I haven't seen examples of its use in the context of matplotlib, or specifically the engineering ticker. It may be beyond scope to address this issue, but ideally, we would deal with internationalisation/localisation of these units as we have elsewhere in the project for translations.
The text was updated successfully, but these errors were encountered: