您可以使用meshgrid
來生成點的網格。如果您的採樣x和y是均勻的,那麼只需在每個方向上加上分隔2。即,如果分離是1,再加入0.5和減1分:
import numpy as np
import matplotlib.pyplot as plt
r = np.arange(10)
p = np.arange(10)
R,P = np.meshgrid(r,p)
data = np.random.random((10,10))
plt.pcolor(R,P,data)
plt.scatter(R[:-1,:-1]+0.5,P[:-1,:-1]+0.5, color = 'blue')
這是如果你使用tripcolor
: 你可以計算你點的質心:triang.triangles
給你三點每個三角形的索引,然後使用這三個點計算質心。即centroidX = (x1+x2+x3)/3.; centroidY = (y1+y2+y3)/3.;
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.tri as tri
x = np.random.random(10)
y = np.random.random(10)
z = np.random.random(10)
triang = tri.Triangulation(x, y)
plt.tripcolor(triang,z)
centroidX = [x[i].sum()/3. for i in triang.triangles]
centroidY = [y[i].sum()/3. for i in triang.triangles]
plt.scatter(centroidX,centroidY, color = 'blue')
能否請您分享更多的代碼,所以我們有一個比較清晰的起點? – Abdou
@Abdou當然,但它確實簡單地調用'pcolor'然後'scatter'。但是,是的,我會更新 – Andy