从Python中的坐标表绘制3-D曲面

时间:2019-03-08 20:41:19

标签: python python-3.x matplotlib

我还没有找到答案:我有一个在文本文件中定义的网格,该网格有四列:(lon,lat,depth,slip)。每行都是一个网格点。

我可以使用以下简单代码生成这些点的散点图:

# Main imports:
import numpy as np
from pylab import *
from mpl_toolkits.mplot3d import Axes3D

# Read the grid:
points = np.loadtxt("grid.txt")

# Retrieve parameters from the grid:
lon = points[:,0]
lat = points[:,1]
depth = points[:,2]
slip = points[:,3]

# 3-D plot of the model:
fig = figure(1)
ax = fig.add_subplot(111, projection='3d')
p = ax.scatter(lon, lat, depth, c=slip, vmin=0, vmax=max(slip), s=30, edgecolor='none', marker='o')
fig.colorbar(p)
title("Published finite fault in 3-D")
ax.set_xlabel("Longitude [degrees]")
ax.set_ylabel("Latitude [degrees]")
ax.set_zlabel("Depth [km]")
ax.invert_zaxis()
jet()
grid()
show()

我得到下图: Grid in 3-D. The color of each point represents the "slip" values. 我想要做的是能够对这些点进行插值,以创建“连续”曲面网格并将其绘制在2-D和3-D图中。因此,我必须以某种方式考虑插值中的所有(lon,lat,depth,slip)。非常感谢您的建议。预先感谢!

1 个答案:

答案 0 :(得分:0)

我来晚了一点,但是如果您的数据网格排序正确,则可以使用plot_surface将一维数据重塑为二维来解决iusse问题。 假设您使用10x10网格的示例:

h2 = {}
array_2.each do |g|
  arr = [g[:locality], g[:neighbourhood]]
  h2[arr] = [] unless h2.key?(arr)
  h2[arr] << g
end
h2      
相关问题