X Tutup
Skip to content

Proof of concept images with units#19481

Closed
dstansby wants to merge 1 commit intomatplotlib:masterfrom
dstansby:image-units
Closed

Proof of concept images with units#19481
dstansby wants to merge 1 commit intomatplotlib:masterfrom
dstansby:image-units

Conversation

@dstansby
Copy link
Copy Markdown
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
self.mappable = mappable
_add_disjoint_kwargs(kwargs, cmap=mappable.cmap, norm=mappable.norm)

# Set the formatter if
Copy link
Copy Markdown
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
Copy Markdown
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

X Tutup