Skip to content
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

ignore singleton dimensions in ndarrays passed to imshow #1774

Closed
wants to merge 1 commit into from

Conversation

tacaswell
Copy link
Member

instigated by this: http://stackoverflow.com/questions/15008045/showing-an-image-with-pylab-imshow/15008830#15008830

This just gets rid of singleton dimensions in ndarrays that are passed in.

@efiring
Copy link
Member

efiring commented Feb 21, 2013

First, this is not fixing a bug, so if it should go anywhere, it should be into master, not 1.2.x.

Second, I think this is a slippery slope, and it is not clear to me that we should start sliding down it. There is a balance between ease-of-use and trying to be too clever--assuming we know what the user wanted, instead of letting the user specify what is desired. I think this squeeze is going too far in the direction of "do what we think the user proabably wanted, not what the user specified". I don't see a good justification for it.

@tacaswell
Copy link
Member Author

I seem to be consistently target the wrong branch.

As I was typing my defense of this not being too far down the slope, I convinced my self I am wrong.

This blows up the use case of a (M, 1, [3, 4]) array.

@tacaswell tacaswell closed this Feb 21, 2013
@mdboom
Copy link
Member

mdboom commented Feb 21, 2013

Aside from the details of the implementation (which has a buglet as you point out) and the branch this should go on (I think master), I actually think the premise is a good one.

This makes greyscale (single plane) images behave in a similar way to RGB and RGBA images. Therefore the expected dimensions of the image are always (height, width, planes), rather than (height, width, planes if planes > 1) and the onus is removed from the user to determine which kind of the three they have before passing the image to matplotlib. Of course, we can't, for backward compatibility and issues of making obvious and simple things work, remove the ability to just pass in a 2D image. But I'd be in favor of adding something like:

if array.dims == 3 and array.shape[2] == 1:
   array = array.reshape(array.shape[:2])

@tacaswell
Copy link
Member Author

@mdboom Do you want/need me to do anything else about this at this point?

@mdboom
Copy link
Member

mdboom commented Feb 22, 2013

I think if there's consensus about moving forward with this idea, we can go ahead with an implementation that does something a little more specific than what squeeze does... but there may be more to discuss first...

@dmcdougall
Copy link
Member

I think that judging by that Stack Overflow question, this is more of a documentation bug than a code bug. We should be more explicit in saying what matplotlib expects. In addition to @efiring's point, if matplotlib starts being a little more clever about assuming what the user wanted, we also have to document this behaviour on top of documenting explicitly what matplotlib expects.

@tacaswell tacaswell deleted the imshow_squeeze branch December 27, 2016 23:28
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.

None yet

4 participants