簡體   English   中英

輪廓和輪廓f的使用

[英]use of contour and contourf

我有一個要點列表:

pointList = [ [x1,y1,z1], [x2,y2,z2], ... [xn,yn,zn]]

我想繪制這組點的等高線圖。

我嘗試:

import matplotlib.pyplot as plt
pointList = [ [x1,y1,z1], [x2,y2,z2], ... [xn,yn,zn]]
x = [el[0] for el in pointList]
y = [el[1] for el in pointList]
z = [el[2] for el in pointList]
plt.contourf(x,y,z)
plt.show()

但我有這個例外:

TypeError: Input z must be a 2D array.

這很奇怪,因為在 matplotlib 的文檔中我發現:

Call signatures:
contour(Z)
make a contour plot of an array Z. The level values are chosen automatically.
contour(X,Y,Z)
X, Y specify the (x, y) coordinates of the surface

所以我不明白為什么它失敗了......

在任何一種情況下, contour(Z)contour(X,Y,Z) ,輸入Z必須是二維數組。

如果您的數據不在網格上,您要么需要將其插入到網格中,要么不能使用等高線。

一個簡單的替代方法是使用tricontour

import matplotlib.pyplot as plt
import numpy as np
pointList = [ [x1,y1,z1], [x2,y2,z2], ... [xn,yn,zn]]
pointList = np.array(pointList)
plt.tricontour(pointList[:,0],pointList[:,1],pointList[:,2])
plt.show()

有一個很好的示例將tricontour與插值數據的contour進行比較: tricontour_vs_griddata

您還可以查看:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM