Dear matplotlib

I have a newbie question (I am new to python, migrating from Matlab). Just

like the subject suggests, I need to display an image X stored in a matrix

(well, a 2D numpy array in fact) versus the coordinates specified by arrays

x and y. Further, it would be nice if mouse position was returned in terms

of those coordinates as well, but that's just for a nicety - I can map it

myself. But main thing is I failed to find the way to get the image

versuscoordinates in imshow() and figimage(). I also failed to find the

answer in this forum.

Hence I ask for any suggestions.

## ···

–

View this message in context: http://www.nabble.com/does-matplotlib-have-an-analog-to-imagesc(x%2Cy%2CX)-of-Matlab--tp16323613p16323613.html

Sent from the matplotlib - users mailing list archive at Nabble.com.

Vsevolod Kovalenko wrote:

Dear matplotlib

I have a newbie question (I am new to python, migrating from Matlab). Just

like the subject suggests, I need to display an image X stored in a matrix

(well, a 2D numpy array in fact) versus the coordinates specified by arrays

x and y. Further, it would be nice if mouse position was returned in terms

of those coordinates as well, but that's just for a nicety - I can map it

myself. But main thing is I failed to find the way to get the image

versuscoordinates in imshow() and figimage(). I also failed to find the

answer in this forum.

Hence I ask for any suggestions.

There is not an *exact* clone of imagesc, but you can certainly get the same effect. Note that imshow has an origin kwarg that lets you specify the vertical orientation, and an extent kwarg that controls the mapping between pixels and your X and Y scales. If you want direct indexing into a colormap you can get it with the kwarg norm=mpl.colors.NoNorm(), provided your Z array has an integer dtype and includes values within the range of the colormap; the default colormaps all have 256 colors.

An alternative, if you want to specify the boundaries of the pixels rather than their centers (or if you have unevenly-spaced boundaries), is pcolor, or pcolormesh. If you have a recent version of mpl you can use the Axes method pcolorfast.

Offhand, though, it sounds like imshow() with suitable kwargs will do exactly what you want. See image_demo2.py in the mpl examples directory.

Eric