0

python(例如matplotlib)可以制作如下图,其中颜色表示每个数据点的强度?谢谢!

在此处输入图像描述

4

3 回答 3

3

如果您希望鼠标报告鼠标下数据的值,则只需要所有这些机器。要生成图像,您真正需要的是 (doc)

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

cmap您可以通过关键字控制颜色映射。

于 2013-01-22T19:27:29.403 回答
2

这是取自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()
于 2013-01-22T18:29:07.243 回答
1

您正在寻找image_zcode给出的示例是:

"""
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()
于 2013-01-22T18:28:02.997 回答