Форум сайта python.su
0
Здравствуйте. Хочу построить поверхность земли по координатам и отметкам точек. Для получения дополнительных точек поверхности использую scipy.interpolation.griddata. Не пойму почему в некоторых точках функция возвращает nan и поверхность не строится в этих точках. Помогите разобраться.
import numpy as np from scipy.interpolate import griddata from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt x_list = np.array([54.0, 54.0, 24.0, 24.0, 24.0, 24.0, 0.0, 0.0, 0.0]) y_list = np.array([40.0, 20.0, 0.0, 40.0, 20.0, 0.0, 40.0, 20.0, 0.0]) z_list = np.array([105.4, 104.5, 103.65, 105.45, 104.7, 103.95, 105.5, 104.85, 104.25]) xi = np.linspace(min(x_list), max(x_list)) yi = np.linspace(min(y_list), max(y_list)) grid_x, grid_y = np.meshgrid(xi, yi) grid_z1 = griddata((x_list, y_list), z_list, (grid_x, grid_y), method='nearest') grid_z2 = griddata((x_list, y_list), z_list, (grid_x, grid_y), method='linear') grid_z3 = griddata((x_list, y_list), z_list, (grid_x, grid_y), method='cubic') print grid_z2 fig = plt.figure() ax1 = fig.add_subplot(221, projection='3d') surf = ax1.plot_surface(grid_x, grid_y, grid_z1) ax2 = fig.add_subplot(222, projection='3d') surf = ax2.plot_surface(grid_x, grid_y, grid_z2) ax3 = fig.add_subplot(223, projection='3d') surf = ax3.plot_surface(grid_x, grid_y, grid_z3) plt.show()
Отредактировано __Ak1m__ (Ноя. 14, 2014 10:32:32)
Офлайн
0
Мой косяк оказался. Я одну точку забыл.
import numpy as np from scipy.interpolate import griddata from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt x_list = np.array([54.0, 54.0, 54.0, 24.0, 24.0, 24.0, 24.0, 0.0, 0.0, 0.0]) y_list = np.array([40.0, 20.0, 0.0, 0.0, 40.0, 20.0, 0.0, 40.0, 20.0, 0.0]) z_list = np.array([105.4, 104.5, 103.65, 103.65, 105.45, 104.7, 103.95, 105.5, 104.85, 104.25]) xi = np.linspace(min(x_list), max(x_list)) yi = np.linspace(min(y_list), max(y_list)) grid_x, grid_y = np.meshgrid(xi, yi) grid_z1 = griddata((x_list, y_list), z_list, (grid_x, grid_y), method='nearest') grid_z2 = griddata((x_list, y_list), z_list, (grid_x, grid_y), method='linear') grid_z3 = griddata((x_list, y_list), z_list, (grid_x, grid_y), method='cubic') print grid_z2 ##z1 = grid_z2 = griddata((x_list, y_list), z_list, (grid_x, grid_y), method='linear') fig = plt.figure() ax1 = fig.add_subplot(221, projection='3d') surf = ax1.plot_surface(grid_x, grid_y, grid_z1) ax2 = fig.add_subplot(222, projection='3d') surf = ax2.plot_surface(grid_x, grid_y, grid_z2) ax3 = fig.add_subplot(223, projection='3d') surf = ax3.plot_surface(grid_x, grid_y, grid_z3) plt.show()
Офлайн