没人写过或者看过类似的代码么?
简单的说就是:已知一个形状边界点上的颜色(其实就是颜色),在形状中建立一个多点之间的渐变填充模式,对其进行填充
程序代码:
import numpy as np
from scipy.interpolate import griddata
import matplotlib.pyplot as plt
# 4 Point Sample Data
#x=np.array([7.071067812,10,7.071067812,1.22515E-15])
#y=np.array([7.071067812,6.12574E-16,-7.071067812,-10])
#z=np.array([0.322,0.337,0.379,0.344])
# 8 Point Sample Data
# x=np.array([7.071067812,10,7.071067812,1.22515E-15,-7.071067812,-10,-7.071067812,-2.4503E-15])
# y=np.array([7.071067812,6.12574E-16,-7.071067812,-10,-7.071067812,-1.83772E-15,7.071067812,10])
# z=np.array([0.322,0.337,0.379,0.344,0.328,0.331,0.435,0.386])
# 12 Point Sample Data
x = np.array([5,8.660254038,10,8.660254038,5,1.22515E-15,-5,-8.660254038,-10,-8.660254038,-5,-2.4503E-15])
y = np.array([8.660254038,5,6.12574E-16,-5,-8.660254038,-10,-8.660254038,-5,-1.83772E-15,5,8.660254038,10])
z = np.array([0.006,0.021,0.063,0.028,0.012,0.015,0.119,0.07,0.071,0,0.003,0.054])
def plot_contour(x,y,z,resolution = 50,contour_method='linear'):
resolution = str(resolution)+'j'
X,Y = np.mgrid[min(x):max(x):complex(resolution), min(y):max(y):complex(resolution)]
points = [[a,b] for a,b in zip(x,y)]
Z = griddata(points, z, (X, Y), method=contour_method)
return X,Y,Z
X,Y,Z = plot_contour(x,y,z,resolution = 500,contour_method='cubic')
with plt.style.context("seaborn-white"):
fig, ax = plt.subplots(figsize=(13,13))
ax.scatter(x,y, color="Red", linewidth=1, edgecolor="ivory", s=50)
ax.contourf(X, Y, Z, cmap="rainbow")
fig.show()