Revision: 5188
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5188&view=rev
Author: jdh2358
Date: 2008-05-18 15:31:59 -0700 (Sun, 18 May 2008)
Log Message:
-----------
added z coordinate example for nearest neighbor images
Added Paths:
-----------
trunk/matplotlib/examples/api/image_zcoord.py
Added: trunk/matplotlib/examples/api/image_zcoord.py
===================================================================
--- trunk/matplotlib/examples/api/image_zcoord.py
(rev 0)
+++ trunk/matplotlib/examples/api/image_zcoord.py 2008-05-18 22:31:59 UTC
(rev 5188)
@@ -0,0 +1,27 @@
+"""
+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()
+
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
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-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins