Former-commit-id:a02aeb236c
[formerly9f19e3f712
] [formerlya02aeb236c
[formerly9f19e3f712
] [formerly06a8b51d6d
[formerly 64fa9254b946eae7e61bbc3f513b7c3696c4f54f]]] Former-commit-id:06a8b51d6d
Former-commit-id:8e80217e59
[formerly3360eb6c5f
] Former-commit-id:377dcd10b9
27 lines
643 B
Python
Executable file
27 lines
643 B
Python
Executable file
"""
|
|
Show how to modify the coordinate formatter to report the image "z"
|
|
value of the nearest pixel given x and y
|
|
"""
|
|
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()
|
|
|