Skip to content

Allow use of unitful data in images #19476

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

Open
dstansby opened this issue Feb 8, 2021 · 5 comments · May be fixed by #27721
Open

Allow use of unitful data in images #19476

dstansby opened this issue Feb 8, 2021 · 5 comments · May be fixed by #27721
Labels
keep Items to be ignored by the “Stale” Github Action New feature topic: units and array ducktypes

Comments

@dstansby
Copy link
Member

dstansby commented Feb 8, 2021

Problem

Often the data stored in images can have physical values associated with them. It would therefore be good if there was support for using the unit machinery to allow images to have units.

Proposed Solution

Here's a short example that should work fine using units, but which currently fails. The use of datetime is a bit contrived, but I chose it to avoid a third party package. For a more realistic real-world example see astropy/astropy#11306.

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

data = [[datetime.now(), datetime.now()],
        [datetime.now(), datetime.now()]]

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

plt.show()

This fails in

  File "/Users/dstansby/github/matplotlib/lib/matplotlib/axes/_axes.py", line 5586, in imshow
    im.set_data(X)
  File "/Users/dstansby/github/matplotlib/lib/matplotlib/image.py", line 700, in set_data
    raise TypeError("Image data of dtype {} cannot be converted to "
TypeError: Image data of dtype object cannot be converted to float
@jklymak
Copy link
Member

jklymak commented Feb 8, 2021

Crossref #7383 and #11422 where this is discussed....

@jklymak
Copy link
Member

jklymak commented Feb 8, 2021

Re-engineering data handling to make this possible in general is the goal of the Chan-Zuckerberg proposal that just was renewed. I'm not sure if something practical like this should be done in the more immediate term. Adding a converter to everything that could use a converter is possible, but will likely end up causing some pain at somepoitn without some proper engineering. ie. suppose I want to change the z-data of the image in an animation?

@dstansby
Copy link
Member Author

dstansby commented Feb 8, 2021

Ah apologies, I didn't find #7383 in my searches before opening this issue. Happy to close this and divert discussion there.

@jklymak
Copy link
Member

jklymak commented Feb 8, 2021

Well that discussion was just for categorical, so pointing out that it is more general is useful.

@github-actions
Copy link

github-actions bot commented Oct 6, 2023

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!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Oct 6, 2023
@story645 story645 added keep Items to be ignored by the “Stale” Github Action and removed status: inactive Marked by the “Stale” Github Action labels Oct 6, 2023
@dstansby dstansby linked a pull request Jan 30, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep Items to be ignored by the “Stale” Github Action New feature topic: units and array ducktypes
Projects
None yet
3 participants