Ken Schutte wrote:
If I display a simple matrix with imshow(), e.g:
a = zeros((3,3))
a[0,0] = 1
the axes extend from 0.0 to 3.0 in such a way that elements are centered at 0.5, 1.5,... For example, the point at (x,y)=(.9,.9) is red, whereas nearest-interp. should give a[1,1]=0. Would it make more sense for the default to be like this (as is in matlab): ?
imshow(a,interpolation='nearest',extent=(-0.5, 2.5, -0.5, 2.5))
Actually, the matlab nearest equivalent would be
imshow(a, interpolation='nearest', extent=(-0.5, 2.5, 2.5, -0.5))
so that the y-axis increases down and both axes correspond to the array indices. I agree that this makes good sense. It seems to me that in the long run it would make imshow easier to explain and easier to use.
Is there a way to get behavior this automatically?
Not at present without defining your own little function to set the extent. It would be easy to change imshow to work this way, so the question is whether enough other users would prefer it and whether it would cause too much disruption. It could also be made optional via a new kwarg or a new interpretation of an old kwarg. For example, extent could take a string to indicate this option, something like "extent='indices'". An rc param could control the default.
Some discussion (and/or a ruling by John) is needed. My preference is that if a change is made, it be a change in basic default behavior, not additional options, because any non-default behavior can be achieved easily using the extent kwarg in its present form, and at some point adding options and more complicated handling of kwargs causes more trouble (complex code and documentation) than it is worth. I don't see any advantage of the present behavior over the matlab-equivalent behavior--but that may be because I am ignorant of the original rationale.
If imshow behavior is changed, a corresponding change will be needed in the image-matching capability of contour. Maybe matshow would also change; I haven't checked.