2013-01-22 50 views
0

python(例如matplotlib)可以像下面這樣繪製瓦塊圖,其中顏色表示每個數據點的強度?謝謝!蟒蛇可以做一個瓷磚陰謀嗎?

enter image description here

+1

http://matplotlib.org/examples/api/image_zcoord.html – NPE

+0

@TheodrosZelleke你的網址被破壞,http://stackoverflow.com/questions/14391959/heatmap-in-matplotlib-with-pcolor – tacaswell

+0

@tcaswell無法編輯它 - 所以我刪除它 –

回答

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() 
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() 
3

你只需要所有的臨如果您希望鼠標在您的鼠標下報告數據的值,可以使用機器。生成圖像你真正需要的是(doc)

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

您可以通過cmap關鍵字控制顏色映射。