Description
Problem
I would like to define and use a custom unit converter class. The existing mpl.units.registry
system is type-based, which does not work for my usecase. I need my converter to generalize over types. But I also know exactly which (existing) axis objects should use the converter.
The closest I can get in associating a custom converter with an existing axis, following the code in axis.update_units
is
ax = plt.figure().subplots()
ax.xaxis.converter = CustomConverter()
ax.xaxis._update_axisinfo()
ax.xaxis.stale = True
Proposed Solution
A public axis.set_converter
API would solve this problem, e.g.
ax = plt.figure().subplots()
ax.set_converter(CustomConverter())
The idea is that this would basically do what Axis.update_units
does, but consuming a ConversionInterface
rather than consuming data and then getting a converter from the registry.
Additional context and prior art
The other thing I would mention is that I could probably work-around this problem if the registry lookup were based on the container dtype
rather than the type of the individual elements (as is currently the case). But that seems to complexify the existing API, whereas the this proposal would add an orthogonal API, and it is probably better for that reason.