2017-05-29 31 views
2

將matplotlib版本從1.3.1更新到2.0.2後,當我想用​​plot_trisurf生成一個3d點的TIN時,我得到了難以理解的結果。我的測試代碼如下:matplotlib的Plot_trisurf 2.0.2

import sys 
import matplotlib 
import matplotlib.pyplot as plt 
from matplotlib.ticker import MaxNLocator 
from matplotlib import cm 
from mpl_toolkits.mplot3d import Axes3D 
import numpy 
from numpy.random import randn 
from scipy import array, newaxis 

chunk = numpy.loadtxt('test.xyz') #test.xyz contains 38010 points, 
DATA=numpy.array(chunk) 
Xs = DATA[:,0] 
Ys = DATA[:,1] 
Zs = DATA[:,2] 

fig = plt.figure() 
ax = fig.add_subplot(111, projection='3d') 

surf = ax.plot_trisurf(Xs, Ys, Zs, cmap=cm.jet, linewidth=0) 
fig.colorbar(surf) 

ax.xaxis.set_major_locator(MaxNLocator(5)) 
ax.yaxis.set_major_locator(MaxNLocator(6)) 
ax.zaxis.set_major_locator(MaxNLocator(5)) 

fig.tight_layout() 
plt.show() 

test.xyz文件包含38010個點。它的一部分顯示如下,完整的文件可以找到here

512743.63 5403547.33 308.68 
512743.62 5403547.33 308.70 
512743.61 5403547.33 308.72 
512743.60 5403547.34 308.68 
512743.60 5403547.33 308.73 
512741.50 5403547.36 309.05 
512741.50 5403547.36 309.07 
512741.49 5403547.46 309.09 
512741.48 5403547.46 309.07 
512741.47 5403547.46 309.10 
512741.47 5403547.45 309.13 
512741.46 5403547.37 309.04 
512739.39 5403547.51 309.10 
512739.39 5403547.48 309.34 
512739.38 5403547.60 309.25 
512739.37 5403547.71 309.15 
512739.39 5403547.49 310.65 
512739.39 5403547.48 310.70 
512739.38 5403547.49 310.69 
512739.37 5403547.48 310.72 
512739.36 5403547.39 310.64 
512739.32 5403547.41 309.20 
512737.33 5403547.26 313.14 
512737.33 5403547.37 313.09 
512737.32 5403547.38 313.03 
512737.30 5403547.37 313.12 
512737.30 5403547.26 313.14 
512735.22 5403547.41 311.72 
512735.22 5403547.43 312.29 
512735.22 5403547.49 312.59 
512735.21 5403547.51 312.48 
512735.20 5403547.60 312.53 
512735.19 5403547.61 312.48 
512735.18 5403547.72 312.40 
512735.18 5403547.71 312.49 
512735.17 5403547.71 312.51 
512735.16 5403547.70 312.58 
512735.15 5403547.61 312.52 

更新後,顯示的結果爲:]

我認爲這是錯誤的,因爲我提供足夠的積分來生成TIN,但結果似乎只使用點的一小部分。更新matplotlib之前,我能得到這樣的結果: ]

+0

謝謝你的回覆,但我提供了一個包含38010點的文件。以上數據只顯示很小的一部分,爲了說明數據格式 – zxgao

+0

詳細顯示在[link](https://github.com/zxgdll/problem-about-matplotlib2.0.2) – zxgao

+0

我可以證實trisurf圖只繪製了一個點的子集。我不知道這個原因,但它必須在三角形或trisurf陰謀本身的某個地方。我向你提出的[GitHub問題](https://github.com/matplotlib/matplotlib/issues/8682)添加了一些可重複的代碼。 – ImportanceOfBeingErnest

回答

0

非常感謝所有答覆。此問題已解決,詳細情況已在Problem about plot_trisurf of matplotlib 2.0.2中顯示。 在這裏,我很高興地展示我的結果。 這個問題是在qhull中計算Delaunay三角剖分時的有限精度問題之一,它考慮的是靠近的點(根據'near'這個詞的複雜定義)是相同的,所以三角測量比期望的要簡單。對於有限精度的數據集來說是一個極端的(壞的方式),因爲點的平均點擴展很小(x.mean()= 512767,x.max() - x.min()= 134,y .mean()= 303,y.max() - y.min()= 5403707)。這由Ian Thomas解釋。 因此,我已經改正了我的測試代碼如下:

import sys 
import matplotlib 
import matplotlib.pyplot as plt 
from matplotlib.ticker import MaxNLocator 
from matplotlib import cm 
from mpl_toolkits.mplot3d import Axes3D 
import numpy 
from numpy.random import randn 
from scipy import array, newaxis 

chunk = numpy.loadtxt('test.xyz') #test.xyz contains 38010 points, 
DATA=numpy.array(chunk) 
Xs = DATA[:,0] 
Ys = DATA[:,1] 
Zs = DATA[:,2] 

fig = plt.figure() 
ax = fig.add_subplot(111, projection='3d') 
#surf = ax.plot_trisurf(Xs, Ys, Zs, cmap=cm.jet, linewidth=0) 
surf = ax.plot_trisurf(Xs-Xs.mean(), Ys-Ys.mean(), Zs, cmap=cm.jet, linewidth=0) 
fig.colorbar(surf) 

ax.xaxis.set_major_locator(MaxNLocator(5)) 
ax.yaxis.set_major_locator(MaxNLocator(6)) 
ax.zaxis.set_major_locator(MaxNLocator(5)) 

fig.tight_layout() 
plt.show() 

,之前顯示的結果爲:,結果顯示爲 enter image description here

後: enter image description here

所以總結這起來,這實際上不是matplotlib版本之間的問題,而且當前版本足以應付大多數用例。如果有人希望軸ticklabes可以很容易地糾正,你可以參考ImportanceOfBeingErnest的method.