Skip to content

Proof of concept images with units #19481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

dstansby
Copy link
Member

@dstansby dstansby commented Feb 8, 2021

xref #19476

There is likely lots to iron out, and many tests and documentation that would need adding, but I thought I would open this as a proof of concept for images (or more generally mappables) with units. Things that come to mind are:

  • Unit converters expect an axis argument, I'm not sure what to do about this when we have a mappable and not an axis
  • munits.registry.get_converter expects a 1D sequence as input, not 2D, there's probably a way to modify this though

This allows things like this image, where the correct formatter is automatically set on the colorbar:

imshow-dates

from datetime import datetime, timedelta
import matplotlib.colors as mcolor
import matplotlib.pyplot as plt

data = [[datetime.now(), datetime.now() - timedelta(seconds=1)],
        [datetime.now(), datetime.now()]]

fig, ax = plt.subplots()
im = ax.imshow(data)
fig.colorbar(im)

plt.show()

@jklymak jklymak marked this pull request as draft February 8, 2021 15:09
@@ -1174,6 +1174,17 @@ def __init__(self, ax, mappable, **kwargs):
self.mappable = mappable
_add_disjoint_kwargs(kwargs, cmap=mappable.cmap, norm=mappable.norm)

# Set the formatter if
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #18900 for changes in how the formatter and locator will work in 3.5

@dstansby
Copy link
Member Author

dstansby commented Feb 8, 2021

Thanks for bringing #18900 to my attention. With the context of that and the CZI grant, I think it's probably worth closing this (currently) bare bones attempt to wait for colorbar refactoring and a bit more thought.

@dstansby dstansby closed this Feb 8, 2021
@dstansby dstansby deleted the image-units branch September 1, 2021 11:33
@dstansby dstansby mentioned this pull request Sep 1, 2021
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants