Skip to content

Showing np.uint16 images of the form (h,w,3) is broken #2499

Closed

Description

@luispedro

Here is a simple test case:

import matplotlib.pyplot as plt
import numpy as np
A = np.array([np.arange(256,dtype=np.uint16) for _ in xrange(256)])
B =  (A<<8)+(255*np.random.random(A.shape)).astype(np.uint16)
B = np.dstack([B,B,B])
plt.imshow(B)
plt.show()

This results in random bits.

The problem is in file lib/matplotlib.cm.py: the conversion to np.uint8 assumes that the input is in 0..1 format.

Activity

  1. tacaswell commented on Oct 6, 2013

    @tacaswell
    Member

    To be fair, the docs (http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.imshow) only claim to support float or uint8 so I would not call this broken.

  2. luispedro commented on Oct 7, 2013

    @luispedro
    ContributorAuthor

    Then, maybe the real bug is that it doesn't raise an exception :)

    It's certainly surprising behaviour.

  3. added a commit that references this issue on Oct 8, 2013
  4. tacaswell commented on Nov 29, 2013

    @tacaswell
    Member

    @luispedro Can you make a PR with that fix?

  5. added this to the milestone on Aug 17, 2014
  6. self-assigned this
    on Mar 7, 2016
  7. added a commit that references this issue on Mar 7, 2016
    c2f91c5
  8. added a commit that references this issue on Mar 7, 2016
    7df8f0d
  9. tacaswell commented on Mar 7, 2016

    @tacaswell
    Member

    @luispedro Thanks, sorry this took so long to get resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

API: changesChanges to the public API, typically requiring deprecation.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions