You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[MNT]: Alternate unit conversion and array duck typing. #23015
Units are inconsistent and only partially functional, particularly when combined with duck-typing array types.
Proposed fix
Matplotlib has had support for units for many years. There have been two main uses for this functionality,
to convert data objects to numpy arrays
to allow the units to change on an axis (ax.xaxis.set_units('feet')).
The first functionality generally works, and works well. However the second is only supported by plot. That is because plot retains the unit information, and Line2d reevaluates it at draw time. Unfortunately, no other plotting methods do this.
Here we propose to back this out of Line2D and instead convert at the beginning. So at the beginning of any plotting routine we will call x = ax.xaxis.convert_units(x). If xaxis already has a unit converter, that will get called with x as an argument. If not, then the units registry will be consulted and the unit converter added to xaxis. Data will always be stored as a numpy array with some base units. So if we have 'feet', 'miles', 'meters', we would convert and store x in units of meters (or whatever the converter prefers).
This leaves dealing with changing the units on the axis, which works for plot/Line2D but not other artists. This can be done one of two ways
Just change the axis Locator and Formatter to the new units. This is currently what dates.py does already for different date resolutions. This has the benefit of keeping the data units the same as the numpy values stored by the Artist
The more complicated method would be via another transform going from internal data to display data
Overall, I think 1) is the easiest, but it does require folks with unit converters writing more flexible locators and formatters.
I note that this is the opposite direction being suggested by recent proposals to pipe the raw object all the way to the draw stage. But I'm not sure if that will end up successful, so thought I'd make this alternate suggestion.
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
Activity
github-actions commentedon Dec 5, 2025
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
timhoffm commentedon Dec 5, 2025
Hi does this relate to the data prototype work?
story645 commentedon Dec 5, 2025
Its supposed to, the new data objects are supposed to I think move the unit handling to the data object or better sync it. @ksunden?
timhoffm commentedon Dec 6, 2025
This means unit handling is addressed there and we do not need to track this separately.