![](/img/trans.png)
[英]Can I make 3D plot in Python where Z is not a function of X,Y -- AttributeError: 'Series' object has no attribute 'has_data'
[英]Python: How can I plot a generic 3D object if I have x, y and z as functions of some parameters?
例如,對於單位球,
x = cos(phi)sin(theta)
y = sin(phi)sin(theta)
z = cos(theta)
我想簡單地繪制phi和theta分別在間隔[0, 2*pi]
和[0, pi]
。
在一般情況下,有沒有辦法做到這一點,即指定
然后得到一個3D圖?
我認為,就Mayavi而言,您將始終會自己創建一些網格並繪制結果數據點。但是,使用numpy時,不必太麻煩:
from numpy import pi, sin, cos, mgrid
[phi,theta] = mgrid[0:2*pi:100j,0:pi:100j] # 100 is the amount of steps in the respective dimension
x = cos(phi)*sin(theta)
y = sin(phi)*sin(theta)
z = cos(theta)
from mayavi import mlab
s = mlab.mesh(x, y, z)
mlab.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.