2015-02-06 47 views
1

我有一個x,y位置陣列在一個時間步,但我知道隨着時間的推移,這個範圍將擴大(由圖像範圍已設置)。有沒有辦法讓網格的其餘部分在範圍內爲0,直到它被填充。我的理解是,x,y位置或來自np.histogram2d的地圖本身需要在不同大小的新柵格上重新構建,儘管我不知道如何。到目前爲止,我有:傳播immap熱軸超出極限

heatmap, xedges, yedges = np.histogram2d(x,y, bins=50) 
extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]] 
ax.imshow(heatmap.T, origin='lower',extent=extent,cmap='cubehelix') 
ax.set_xlim([20,220]) 
ax.set_ylim([-1,1]) 

但是,這會導致一個封閉區域。我希望基本上使空白空間變黑,直到新的x,y位置在稍後的時間步中填充它們。

heatmap

回答

0

要獨立地傳入的數據的控制直方圖的程度numpy.histogram2d,指定塊位置作爲陣列。

例如,像:

import numpy as np 
import matplotlib.pyplot as plt 

# Known ranges for the histogram and plot 
xmin, xmax = 20, 220 
ymin, ymax = -1, 1 

# Generate some random data 
x = np.random.normal(48, 5, 100) 
y = np.random.normal(0.4, 0.1, 100) 

# Create arrays specifying the bin edges 
nbins = 50 
xbins = np.linspace(xmin, xmax, nbins) 
ybins = np.linspace(ymin, ymax, nbins) 

# Create the histogram using the specified bins 
data, _, _ = np.histogram2d(x, y, bins=(xbins, ybins)) 

# Plot the result 
fig, ax = plt.subplots() 
ax.imshow(data.T, origin='lower', cmap='cubehelix', aspect='auto', 
      interpolation='nearest', extent=[xmin, xmax, ymin, ymax]) 

ax.axis([xmin, xmax, ymin, ymax]) 
plt.show() 

enter image description here

+0

非常感謝! – Griff 2015-02-06 23:11:35