这个问题五年前就被问过,我认为我们应该用代码来回答它。 @ImportanceOfBeingErnest 的评论是最有帮助的,现在我将每个成分总结为以下代码:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.path import Path
from matplotlib.patches import PathPatch
pts = np.array([(0, 0), (1, 0), (0.78, 1)])
p0 = pts.mean(axis=0)
x0, y0 = p0
L = np.maximum(pts[:, 0].ptp(), pts[:, 0].ptp())
delta = 0.01
x = np.arange(x0 -L, x0 + L, delta)
y = np.arange(y0 -L, y0 + L, delta)
X, Y = np.meshgrid(x, y)
d1 = np.sqrt((X-pts[0][0])**2 + (Y-pts[0][1])**2)
d2 = np.sqrt((X-pts[1][0])**2 + (Y-pts[1][1])**2)
d3 = np.sqrt((X-pts[2][0])**2 + (Y-pts[2][1])**2)
eps = 1e-9
d1 = 1/(d1 + eps)
d2 = 1/(d2 + eps)
d3 = 1/(d3 + eps)
d = np.dstack([d1, d2, d3])
d = d/(d.sum(axis=2)[:, :, np.newaxis])
# plot triangle
path = Path(pts)
patch = PathPatch(path, facecolor='none')
fig, ax = plt.subplots(1, 1, figsize=(7.2, 7.2))
ax.add_patch(patch)
im = ax.imshow(d, origin='lower', clip_path=patch, clip_on=True, extent=[x0-L, x0+L, y0-L, y0+L],)
im.set_clip_path(patch)
# plot trinagle points
ax.scatter(pts[:, 0], pts[:, 1], color='k', s=50)
Output: