您要查找的功能包含在^{}中。在
从其文档中,您将看到它是“smart”,并尝试猜测您是否为点或三角形指定了颜色:The next argument must be C, the array of color values, either
one per point in the triangulation if color values are defined at
points, or one per triangle in the triangulation if color values
are defined at triangles. If there are the same number of points
and triangles in the triangulation it is assumed that color
values are defined at points; to force the use of color values at
triangles use the kwarg facecolors=C instead of just C.
继续你的例子:import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial import Delaunay
h = 300
w = 1000
npts = 500
pts = np.zeros((npts,2))
pts[:,0] = np.random.randint(0,w,npts)
pts[:,1] = np.random.randint(0,h,npts)
tri = Delaunay(pts)
plt.xlim(0, w)
plt.ylim(0, h)
centers = np.sum(pts[tri.simplices], axis=1, dtype='int')/3.0
colors = np.array([ (x-w/2.)**2 + (y-h/2.)**2 for x,y in centers])
plt.tripcolor(pts[:,0], pts[:,1], tri.simplices.copy(), facecolors=colors, edgecolors='k')
plt.gca().set_aspect('equal')
plt.show()
这里我只是根据三角形中心和图像中心之间的距离来确定颜色(因为我没有合适的图像)。在
|