Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a smooth surface plot from topographic data using matplotlib

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

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

plot1

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

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

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

Code below

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)
like image 258
Mountain_Madness Avatar asked Nov 09 '22 03:11

Mountain_Madness


1 Answers

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')
like image 51
Atefeh Fazlollahi Avatar answered Nov 14 '22 22:11

Atefeh Fazlollahi