2013-02-13 143 views

回答

3

編輯:我原來的答案用於ax.scatter。沒有與此一個問題:如果兩個點是並排側,ax.scatter可以吸引他們帶着點之間的空間,取決於規模:

例如,

data = np.array([(2,3),(3,3)]) 

這裏是一個放大的細節:

enter image description here

因此,這裏是一個替代的解決方案能解決這個問題:

import matplotlib.pyplot as plt 
import numpy as np 

data = np.array([(2,3),(3,3),(45,4),(3,65)]) 
N = data.max() + 5 

# color the background white (1 is white) 
arr = np.ones((N,N), dtype = 'bool') 
# color the dots black (0) 
arr[data[:,1], data[:,0]] = 0 

fig = plt.figure() 
ax = fig.add_subplot(1, 1, 1) 

ax.imshow(arr, interpolation='nearest', cmap = 'gray') 
ax.invert_yaxis() 
# ax.axis('off') 
plt.show() 

enter image description here

不管你多麼放大,在(2,3)和(3,3)相鄰的廣場將保持並排側。

不幸的是,不像ax.scatter,使用ax.imshow需要構建一個N x N陣列,因此它可能是更多的內存密集型比使用ax.scatter。這應該不是一個問題,除非data包含非常大的數字。

+0

你先生是個傳奇人物。非常感謝你 – 2013-02-13 13:16:31