1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
from mpl_toolkits import mplot3d import matplotlib.pyplot as plt import numpy as np from scipy.interpolate import griddata x = np.array([129, 140, 103.5, 88, 185.5, 195, 105, 157.5, 107.5, 77, 81, 162, 162, 117.5]) y = np.array([7.5, 141.5, 23, 147, 22.5, 137.5, 85.5, - 6.5, -81, 3, 56.5, -66.5, 84, -33.5]) z = -np.array([4, 8, 6, 8, 6, 8, 8, 9, 9, 8, 8, 9, 4, 9]) xy = np.array([x, y]).T xn = np.linspace(x.min(), x.max(), 100) yn = np.linspace(y.min(), y.max(), 100) X, Y = np.meshgrid(xn, yn) zn = griddata(xy, z, (X, Y), method='nearest') ax = plt.subplot(121, projection='3d') ax.plot_surface(X, Y, zn, cmap='viridis') ax.set_xlabel('$x$'), ax.set_ylabel('$y$'), ax.set_zlabel('$z$') plt.subplot(122) a = plt.contourf(X, Y, zn, 8, cmap=plt.cm.Spectral) plt.clabel(plt.contour(xn, yn, zn)) plt.colorbar(a) plt.savefig('griddata.png', dpi=500), plt.show()
|