Can python (eg matplotlib) make a tile plot like the following, where color indicates the intensity at each data point? Thanks!
Asked
Active
Viewed 9,859 times
1
-
1http://matplotlib.org/examples/api/image_zcoord.html – NPE Jan 22 '13 at 18:28
-
@TheodrosZelleke your url is mangled, http://stackoverflow.com/questions/14391959/heatmap-in-matplotlib-with-pcolor – tacaswell Jan 23 '13 at 02:33
-
@tcaswell can't edit it -- so I deleted it – tzelleke Jan 23 '13 at 08:53
3 Answers
2
Here is an example taken from http://matplotlib.org/examples/api/image_zcoord.html:
"""
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()

NPE
- 486,780
- 108
- 951
- 1,012
1
You are looking for image_zcode
The example given is:
"""
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()

PearsonArtPhoto
- 38,970
- 17
- 111
- 142