Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add public API for setting an axis unit converter #19229

Copy link
Copy link
Closed
@mwaskom

Description

@mwaskom
Issue body actions

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.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.