[英]When I use mplot3D, why get error: NameError: name 'plot_trisurf' is not defined
我嘗試使用mplot3D繪制一些3D圖片:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
...
plot_trisurf(X, Y, Z1)
然后我的電腦會告訴我
NameError: name 'plot_trisurf' is not defined
為什么會這樣? 我以為我已經導入了。
plot_trisurf
是Axes3D
類中的方法。 在python中,為了調用類方法,通常需要提供類或它的實例。
在這種情況下,類實例將是您的axes對象。 通常稱為ax
。 因此,正確的調用將是(如在matplotlib trisurf示例上所示 ):
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.gca(projection='3d')
...
ax.plot_trisurf(x, y, z)
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.