你如何径向地“扫除”?在 python 中绘制 3d 图形的 1D 数组? (表示波函数)

发布于 2024-10-02 04:44:44 字数 375 浏览 3 评论 0原文

实际上我有一个大的一维高度数组。作为一个小例子,考虑:

u=array([0,1,2,1,0,2,4,6,4,2,1])

和一个与 u 大小相同的一维数组,其高度对应的径向值,例如:

r=array([0,1,2,3,4,5,6,7,8,9,10])

显然用以下方式绘制这些:

pylab.plot(r,u)

给出了一个漂亮的二维图。

如何将其扫描 360 度,以给出 3D 等值线/曲面图?

如果你能想象它应该看起来像一系列同心的圆形脊,就像原子的波函数一样。

任何帮助将不胜感激!

effectively I have a large 1D array of heights. As a small example consider:

u=array([0,1,2,1,0,2,4,6,4,2,1])

and a 1D array, the same size as u, of radial values which the heights correspond to, e.g.:

r=array([0,1,2,3,4,5,6,7,8,9,10])

Obviously plotting these with:

pylab.plot(r,u)

gives a nice 2D plot.

How can one sweep this out around 360 degrees, to give a 3D contour/surface plot?

If you can imagine it should look like a series of concentric, circular ridges, like for the wavefunction of an atom.

any help would be much appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

り繁华旳梦境 2024-10-09 04:44:44

在这种情况下,你最好使用比 matplotlib 更面向 3D 的东西...

这是一个使用 mayavi:
替代文本

from enthought.mayavi import mlab
import numpy as np

# Generate some random data along a straight line in the x-direction
num = 100
x = np.arange(num)
y, z = np.ones(num), np.ones(num)

s = np.cumsum(np.random.random(num) - 0.5)

# Plot using mayavi's mlab api
fig = mlab.figure()

# First we need to make a line source from our data
line = mlab.pipeline.line_source(x,y,z,s)

# Then we apply the "tube" filter to it, and vary the radius by "s"
tube = mlab.pipeline.tube(line, tube_sides=20, tube_radius=1.0)
tube.filter.vary_radius = 'vary_radius_by_scalar'

# Now we display the tube as a surface
mlab.pipeline.surface(tube)

# And finally visualize the result
mlab.show()

You're better off with something more 3D oriented than matplotlib, in this case...

Here's a quick example using mayavi:
alt text

from enthought.mayavi import mlab
import numpy as np

# Generate some random data along a straight line in the x-direction
num = 100
x = np.arange(num)
y, z = np.ones(num), np.ones(num)

s = np.cumsum(np.random.random(num) - 0.5)

# Plot using mayavi's mlab api
fig = mlab.figure()

# First we need to make a line source from our data
line = mlab.pipeline.line_source(x,y,z,s)

# Then we apply the "tube" filter to it, and vary the radius by "s"
tube = mlab.pipeline.tube(line, tube_sides=20, tube_radius=1.0)
tube.filter.vary_radius = 'vary_radius_by_scalar'

# Now we display the tube as a surface
mlab.pipeline.surface(tube)

# And finally visualize the result
mlab.show()
我很OK 2024-10-09 04:44:44
#!/usr/bin/python

from mpl_toolkits.mplot3d import Axes3D
import matplotlib
import numpy as np
from scipy.interpolate import interp1d
from matplotlib import cm
from matplotlib import pyplot as plt
step = 0.04
maxval = 1.0
fig = plt.figure()
ax = Axes3D(fig)  



u=np.array([0,1,2,1,0,2,4,6,4,2,1])
r=np.array([0,1,2,3,4,5,6,7,8,9,10])
f=interp1d(r,u)

# walk along the circle
p = np.linspace(0,2*np.pi,50)
R,P = np.meshgrid(r,p)
# transform them to cartesian system
X,Y = R*np.cos(P),R*np.sin(P)

Z=f(R)

ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet)
ax.set_xticks([])
plt.show()
#!/usr/bin/python

from mpl_toolkits.mplot3d import Axes3D
import matplotlib
import numpy as np
from scipy.interpolate import interp1d
from matplotlib import cm
from matplotlib import pyplot as plt
step = 0.04
maxval = 1.0
fig = plt.figure()
ax = Axes3D(fig)  



u=np.array([0,1,2,1,0,2,4,6,4,2,1])
r=np.array([0,1,2,3,4,5,6,7,8,9,10])
f=interp1d(r,u)

# walk along the circle
p = np.linspace(0,2*np.pi,50)
R,P = np.meshgrid(r,p)
# transform them to cartesian system
X,Y = R*np.cos(P),R*np.sin(P)

Z=f(R)

ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet)
ax.set_xticks([])
plt.show()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文