On Sun, May 18, 2008 at 4:18 PM, Eric Firing <[EMAIL PROTECTED]> wrote:

> There is nothing standard for this, and you would have to define more
> precisely what you mean by the Z data; what kind of interpolation do you
> want?
>
> This type of request has come up before, and I suspect John may have
> provided an illustration of how to do it in reply to some earlier such
> request, but I don't have any specific pointers.

The question has come up but I don't think I've ever provided a basic
one here, which assumes nearest neihor interpolation and no image
"extent" setting, but it would be fairly easy to generalize to handle
extent:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm

X = 10*np.random.rand(5,3)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.imshow(X, cmap=cm.jet, interpolation='nearest')

numrows, numcols = X.shape
def format_coord(x, y):
    col = int(x+0.5)
    row = int(y+0.5)

    if col>=0 and col<numcols and row>=0 and row<numrows:
        z = X[row,col]
        return 'x=%1.4f, y=%1.4f, z=%1.4f'%(x, y, z)
    else:
        return 'x=%1.4f, y=%1.4f'%(x, y)

ax.format_coord = format_coord
plt.show()


BTW, it appears there are occasional pixel border errors for some
images that I first noticed when playing with this example -- for
example, the image buffer is not filled all the way to the right in
the example code.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to