show Z data for contour plots

When I create a plot with contourf(X,Y,Z) the X and Y data are displayed in text (as usual) in the lower right-hand corner of the figure window. Is there a way to report the Z data as well?

thanks,
-Ryan

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.

Eric

Ryan Dale wrote:

···

When I create a plot with contourf(X,Y,Z) the X and Y data are displayed in text (as usual) in the lower right-hand corner of the figure window. Is there a way to report the Z data as well?

thanks,
-Ryan

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.

···

On Sun, May 18, 2008 at 4:18 PM, Eric Firing <efiring@...202...> 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.