imshow y axis question

I am using imshow to visualise matrices. When I use align='upper' (default), the origin is still displayed in the lower left corner on the axes - i.e. the y-axis is wrong. The data is plotted correctly with the origin in the upper left corner.

Seems to be a bug?

Cheers,
Suresh

Suresh Pillai wrote:

I am using imshow to visualise matrices. When I use align='upper' (default), the origin is still displayed in the lower left corner on the axes - i.e. the y-axis is wrong. The data is plotted correctly with the origin in the upper left corner.

Seems to be a bug?

No, this is just the way it was designed and has always been. You can use the "extent" kwarg to control the axes:

       * origin is either upper or lower, which indicates where the [0,0]
         index of the array is in the upper left or lower left corner of
         the axes. If None, default to rc image.origin
       * extent is a data xmin, xmax, ymin, ymax for making image plots
         registered with data plots. Default is the image dimensions
         in pixels

See the code in axes.spy() for an example of how to get what you want using imshow and the extent kwarg; or use pylab.matshow instead of pylab.imshow. (Probably there should be an axes.matshow convenience method, with pylab.matshow as a wrapper that autogenerates a figure if needed. But at the moment there isn't.)

Eric

···

Cheers,
Suresh

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Great, matshow() works for my requirements.

Although, I must comment that its placement of tickbars seems inappropriate for a matrix visualisation. For example, for the following simple example:

import pylab

matrix = pylab.array([[1,2,3],[4,5,6],[1,1,4]])
pylab.matshow(matrix, cmap=pylab.cm.gray)
pylab.show()

tick marks and labels are produced for [0.5,1.5,2.5] in addition to the appropriate integral ones. It's obviously not an issue for larger matrices.

Further, I would think a setting like align='center' in pylab.bar() would be appropriate. Any simple way of doing this without manually setting the ticks and labels (ironically using forced *.5 ticks)?

I guess I should code and submit it myself. :slight_smile:

Thanks very much,
Suresh

···

On Thu, 1 Mar 2007, Eric Firing wrote:

Suresh Pillai wrote:

I am using imshow to visualise matrices. When I use align='upper'
(default), the origin is still displayed in the lower left corner on the
axes - i.e. the y-axis is wrong. The data is plotted correctly with the
origin in the upper left corner.

Seems to be a bug?

No, this is just the way it was designed and has always been. You can use the "extent" kwarg to control the axes:

      * origin is either upper or lower, which indicates where the [0,0]
        index of the array is in the upper left or lower left corner of
        the axes. If None, default to rc image.origin
      * extent is a data xmin, xmax, ymin, ymax for making image plots
        registered with data plots. Default is the image dimensions
        in pixels

See the code in axes.spy() for an example of how to get what you want using imshow and the extent kwarg; or use pylab.matshow instead of pylab.imshow. (Probably there should be an axes.matshow convenience method, with pylab.matshow as a wrapper that autogenerates a figure if needed. But at the moment there isn't.)

Eric

Cheers,
Suresh

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share
your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Suresh Pillai wrote:

Great, matshow() works for my requirements.

Although, I must comment that its placement of tickbars seems inappropriate for a matrix visualisation. For example, for the following simple example:

import pylab

matrix = pylab.array([[1,2,3],[4,5,6],[1,1,4]])
pylab.matshow(matrix, cmap=pylab.cm.gray)
pylab.show()

tick marks and labels are produced for [0.5,1.5,2.5] in addition to the appropriate integral ones. It's obviously not an issue for larger matrices.

I agree, and this is a problem with spy also. If I remember, I will fix it. It is only a minor annoyance, so it is low priority, though.

There is a difference in the way the axes are labeled between spy and matshow, and I would like to change matshow to agree with spy, unless there is an outcry to the contrary. Specifically, I think the integer axis ticks should land in the middle of a given row or column, not on the edge. To see what I mean, compare

xx = zeros((3,3))
xx[1,1] = 1
spy(xx, marker='s')
to
matshow(xx)

Maybe this is exactly what you mean by your next statement?

Further, I would think a setting like align='center' in pylab.bar() would be appropriate. Any simple way of doing this without manually setting the ticks and labels (ironically using forced *.5 ticks)?

Eric