使用 matplotlib 从地形数据创建平滑表面图 [英] Creating a smooth surface plot from topographic data using matplotlib

查看:41
本文介绍了使用 matplotlib 从地形数据创建平滑表面图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码,可以根据纬度,经度和海拔数据创建3D地形图.

I have a code that creates a 3d topographic surface from lat, lon and elev data.

我正在使用 ax.plot_surface,它创建的地形表面如下所示:

I'm using ax.plot_surface, which creates a topographic surface that looks like this:

我想对数据进行平滑处理,以创建看起来更像这样的图片:

I would like to smooth the data to create a picture that looks more like this:

是否有更好的方法可以平滑网格网格的插值?

Is there a better way to smooth out the interpolation done by mesh grid?

my_data按[lat,lon,elev] size(912,3)

my_data is sorted by [lat,lon,elev] size(912,3)

下面的代码

import os
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from scipy.interpolate import griddata


fig = plt.figure()
ax = Axes3D(fig)
my_data = np.genfromtxt('2014_0.01_v3_HDF5.txt', delimiter = ',',     skip_header = 1)
my_data[my_data==0] = np.nan 
my_data = my_data[~np.isnan(my_data).any(axis=1)]
X = my_data[:,0] 
Y = my_data[:,1]
Z = my_data[:,2]
xi = np.linspace(X.min(),X.max(),(len(Z)/3))
yi = np.linspace(Y.min(),Y.max(),(len(Z)/3))
zi = griddata((X, Y), Z, (xi[None,:], yi[:,None]), method='nearest')

xig, yig = np.meshgrid(xi, yi)

surf = ax.plot_surface(xig, yig, zi, cmap='gist_earth')
fig.colorbar(surf, shrink=0.5, aspect=5)
ax.set_title('2014 ATM Data 0.01 Degree Spacing')
ax.set_xlabel('Latitude')
ax.set_ylabel('Longitude')
ax.set_zlabel('Elevation (m)')
ax.set_zlim3d(0,8000)

推荐答案

您可以替换从最近到三次插值的方法.它为您提供了更好的表面.

You can replace the method of interpolation from nearest to cubic. It gives you a far better surface.

zi = griddata((X, Y), Z, (xi[None,:], yi[:,None]), method='cubic')

这篇关于使用 matplotlib 从地形数据创建平滑表面图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆