3
我有一組座標,說[(2,3),(45,4),(3,65)]
我需要繪製它們作爲基體有反正我可以在matplotlib做到這一點,所以我希望它有這種樣子的http://imgur.com/Q6LLhmk繪製座標爲矩陣matplotlib蟒蛇
我有一組座標,說[(2,3),(45,4),(3,65)]
我需要繪製它們作爲基體有反正我可以在matplotlib做到這一點,所以我希望它有這種樣子的http://imgur.com/Q6LLhmk繪製座標爲矩陣matplotlib蟒蛇
編輯:我原來的答案用於ax.scatter
。沒有與此一個問題:如果兩個點是並排側,ax.scatter
可以吸引他們帶着點之間的空間,取決於規模:
例如,
data = np.array([(2,3),(3,3)])
這裏是一個放大的細節:
因此,這裏是一個替代的解決方案能解決這個問題:
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()
不管你多麼放大,在(2,3)和(3,3)相鄰的廣場將保持並排側。
不幸的是,不像ax.scatter
,使用ax.imshow
需要構建一個N x N
陣列,因此它可能是更多的內存密集型比使用ax.scatter
。這應該不是一個問題,除非data
包含非常大的數字。
你先生是個傳奇人物。非常感謝你 – 2013-02-13 13:16:31