gpt4 book ai didi

python - Matplotlib 在 3d 中绘制脉冲传播

转载 作者:太空狗 更新时间:2023-10-30 00:45:58 25 4
gpt4 key购买 nike

我想在每一步都以这种方式绘制脉冲传播,它绘制了脉冲形状。换句话说,对于 y 的每个值,我想要一系列 x-z 图。像这样的东西(没有颜色): Pulse propagation

如何使用 matplotlib(或 Mayavi)执行此操作?这是我到目前为止所做的:

def drawPropagation(beta2, C, z):
""" beta2 in ps / km
C is chirp
z is an array of z positions """
T = numpy.linspace(-10, 10, 100)
sx = T.size
sy = z.size

T = numpy.tile(T, (sy, 1))
z = numpy.tile(z, (sx, 1)).T

U = 1 / numpy.sqrt(1 - 1j*beta2*z * (1 + 1j * C)) * numpy.exp(- 0.5 * (1 + 1j * C) * T * T / (1 - 1j*beta2*z*(1 + 1j*C)))

fig = pyplot.figure()
ax = fig.add_subplot(1,1,1, projection='3d')
surf = ax.plot_wireframe(T, z, abs(U))

最佳答案

更改为:

ax.plot_wireframe(T, z, abs(U), cstride=1000)

并调用:

drawPropagation(1.0, 1.0, numpy.linspace(-2, 2, 10))

将创建以下图表:

enter image description here

如果你需要用白色填充曲线:

import numpy
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import pyplot
from matplotlib.collections import PolyCollection

def drawPropagation(beta2, C, z):
""" beta2 in ps / km
C is chirp
z is an array of z positions """
T = numpy.linspace(-10, 10, 100)
sx = T.size
sy = z.size

T = numpy.tile(T, (sy, 1))
z = numpy.tile(z, (sx, 1)).T

U = 1 / numpy.sqrt(1 - 1j*beta2*z * (1 + 1j * C)) * numpy.exp(- 0.5 * (1 + 1j * C) * T * T / (1 - 1j*beta2*z*(1 + 1j*C)))

fig = pyplot.figure()
ax = fig.add_subplot(1,1,1, projection='3d')
U = numpy.abs(U)

verts = []
for i in xrange(T.shape[0]):
verts.append(zip(T[i, :], U[i, :]))

poly = PolyCollection(verts, facecolors=(1,1,1,1), edgecolors=(0,0,1,1))
ax.add_collection3d(poly, zs=z[:, 0], zdir='y')
ax.set_xlim3d(numpy.min(T), numpy.max(T))
ax.set_ylim3d(numpy.min(z), numpy.max(z))
ax.set_zlim3d(numpy.min(U), numpy.max(U))

drawPropagation(1.0, 1.0, numpy.linspace(-2, 2, 10))
pyplot.show()

enter image description here

关于python - Matplotlib 在 3d 中绘制脉冲传播,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13240633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com