1

Can python (eg matplotlib) make a tile plot like the following, where color indicates the intensity at each data point? Thanks!

enter image description here

PearsonArtPhoto
  • 38,970
  • 17
  • 111
  • 142
Hailiang Zhang
  • 17,604
  • 23
  • 71
  • 117

3 Answers3

4

You only need all of that machinery if you want the mouse to report back the value of the data under your mouse. To generate the image all you really need is (doc):

plt.imshow(data, interpolation='nearest')

You can control the color mapping via the cmap keyword.

tacaswell
  • 84,579
  • 22
  • 210
  • 199
2

Here is an example taken from http://matplotlib.org/examples/api/image_zcoord.html:

enter image description here

"""
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