我正在使用matplotlib中的plot_surface
函数绘制3D曲面。
我有一个简单的脚本用于绘制表面,其中x,y和z坐标都是基于随机生成的布朗噪声序列:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import scipy.interpolate
np.random.seed(1000)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
num = 50
x_y_z = [[],[],[]]
for i in range(len(x_y_z)):
x_y_z[i] = np.random.randn(num).cumsum()
xs, ys, zs = x_y_z
#xs = np.linspace(1, 25, num)
#ys = np.linspace(1, 25, num)
X, Y = np.meshgrid(xs, ys)
print 'X:', X
print 'Y:', Y
Z = scipy.interpolate.griddata((xs, ys), zs, (X, Y))
ax.plot_surface(X,Y,Z)
plt.show()
这会产生下图(它并不意味着有意义,我只是试验plot_surface
函数):
请注意,在上面的脚本中我注释了两行:
#xs = np.linspace(1, 25, num)
#ys = np.linspace(1, 25, num)
这两行打破scipy.interpolate.griddata
上的脚本,我不知道为什么。基本上我只是试图将布朗噪声x和y坐标切换为简单的线性序列。我收到的错误消息是:
QH6154 qhull precision error: initial facet 1 is coplanar with the interior point
ERRONEOUS FACET:
- f1
- flags: bottom simplicial upperDelaunay flipped
- normal: 0.7071 -0.7071 0
- offset: -0
- vertices: p50(v2) p49(v1) p0(v0)
- neighboring facets: f2 f3 f4
While executing: | qhull d Qz Qbb Qt
Options selected for Qhull 2010.1 2010/01/14:
run-id 1327050034 delaunay Qz-infinity-point Qbbound-last Qtriangulate
_pre-merge _zero-centrum Pgood _max-width 24 Error-roundoff 3.5e-14
_one-merge 2.4e-13 _near-inside 1.2e-12 Visible-distance 6.9e-14
U-coplanar-distance 6.9e-14 Width-outside 1.4e-13 _wide-facet 4.2e-13
precision problems (corrected unless 'Q0' or an error)
2 flipped facets
The input to qhull appears to be less than 3 dimensional, or a
computation has overflowed.
Qhull could not construct a clearly convex simplex from points:
- p32(v3): 17 17 9.7
- p50(v2): 13 13 24
- p49(v1): 25 25 22
- p0(v0): 1 1 0
The center point is coplanar with a facet, or a vertex is coplanar
with a neighboring facet. The maximum round off error for
computing distances is 3.5e-14. The center point, facets and distances
to the center point are as follows:
center point 13.92 13.92 13.87
facet p50 p49 p0 distance= 0
facet p32 p49 p0 distance= 0
facet p32 p50 p0 distance= 0
facet p32 p50 p49 distance= 0
These points either have a maximum or minimum x-coordinate, or
they maximize the determinant for k coordinates. Trial points
are first selected from points that maximize a coordinate.
The min and max coordinates for each dimension are:
0: 1 25 difference= 24
1: 1 25 difference= 24
2: 0 24 difference= 24
If the input should be full dimensional, you have several options that
may determine an initial simplex:
- use 'QJ' to joggle the input and make it full dimensional
- use 'QbB' to scale the points to the unit cube
- use 'QR0' to randomly rotate the input for different maximum points
- use 'Qs' to search all points for the initial simplex
- use 'En' to specify a maximum roundoff error less than 3.5e-14.
- trace execution with 'T3' to see the determinant for each point.
If the input is lower dimensional:
- use 'QJ' to joggle the input and make it full dimensional
- use 'Qbk:0Bk:0' to delete coordinate k from the input. You should
pick the coordinate with the least range. The hull will have the
correct topology.
- determine the flat containing the points, rotate the points
into a coordinate plane, and delete the other coordinates.
- add one or more points to make the input full dimensional.
Traceback (most recent call last):
File "time_dist_unreachable_contour.py", line 21, in <module>
Z = scipy.interpolate.griddata((xs, ys), zs, (X, Y))
File "/usr/lib/python2.7/dist-packages/scipy/interpolate/ndgriddata.py", line 182, in griddata
ip = LinearNDInterpolator(points, values, fill_value=fill_value)
File "interpnd.pyx", line 192, in interpnd.LinearNDInterpolator.__init__ (scipy/interpolate/interpnd.c:2524)
File "qhull.pyx", line 917, in scipy.spatial.qhull.Delaunay.__init__ (scipy/spatial/qhull.c:4030)
File "qhull.pyx", line 170, in scipy.spatial.qhull._construct_delaunay (scipy/spatial/qhull.c:1269)
RuntimeError: Qhull error
任何人都可以解释为什么scipy.interpolate.griddata
可以处理噪音序列,而不是线性序列?
答案 0 :(得分:0)
无法从线上指定的数据进行插值(或有意义的推断)到2D。
如果所有点都在一条线上,则位于两点之间的二维坐标集的测量值为零。