蟒蛇可以制作瓷砖情节吗?

时间:2013-01-22 18:25:34

标签: python matplotlib plot

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

enter image description here

3 个答案:

答案 0 :(得分:3)

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

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

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

答案 1 :(得分:2)

以下是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()

答案 2 :(得分: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()
相关问题