Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Description
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 seeastropy/astropy#11306.
fromdatetimeimportdatetimeimportmatplotlib.colorsasmcolorimportmatplotlib.pyplotaspltdata= [[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",line5586,inimshowim.set_data(X)File"/Users/dstansby/github/matplotlib/lib/matplotlib/image.py",line700,inset_dataraiseTypeError("Image data of dtype {} cannot be converted to "TypeError:Imagedataofdtypeobjectcannotbeconvertedtofloat