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

Allow use of unitful data in images #19476

Copy link
Copy link
Open
@dstansby

Description

@dstansby
Issue body actions

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No 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.