在3D Matplotlib情节脉冲传播 [英] Matplotlib plot pulse propagation in 3d

查看:1977
本文介绍了在3D Matplotlib情节脉冲传播的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在每个步骤绘制脉冲传播以这样的方式,它绘出脉冲形状。换句话说,我希望有一个意甲XZ地块,对于Y​​的每个值。像这样的东西(没有颜色):

我怎样才能做到这一点使用matplotlib(或Mayavi的)?这是我做的,到目前为止:

 高清drawPropagation(β2,C,Z):
    的Beta2的PS /公里
        C是啁啾
        z是Z轴位置数组
    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 *β2 * Z *(1 + 1J * C))* numpy.exp( -  0.5 *(1 + 1J * C)* T * T /(1  -  1J *β2 * Z *(1 + 1J * C)))

    图= pyplot.figure()
    AX = fig.add_subplot(1,1,1,投影='3D')
    冲浪= 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))
 

将创建如下图:

如果您需要的曲线被用白色填充颜色:

 进口numpy的
从mpl_toolkits.mplot3d进口Axes3D
从matplotlib进口pyplot
从matplotlib.collections进口PolyCollection

高清drawPropagation(β2,C,Z):
    的Beta2的PS /公里
        C是啁啾
        z是Z轴位置数组
    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 *β2 * Z *(1 + 1J * C))* numpy.exp( -  0.5 *(1 + 1J * C)* T * T /(1  -  1J *β2 * Z *(1 + 1J * C)))

    图= pyplot.figure()
    AX = fig.add_subplot(1,1,1,投影='3D')
    U = numpy.abs(U)

    绿党= []
    在的xrange I(T.shape [0]):
        verts.append(邮政编码(T [我,:],U [我,:]))

    聚= PolyCollection(绿党,facecolors =(1,1,1,1),edgecolors =(0,0,1,1))
    ax.add_collection3d(聚,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()
 

I'd like to plot pulse propagation in such a way at each step, it plots the pulse shape. In other words, I want a serie of x-z plots, for each values of y. Something like this (without color):

How can I do this using matplotlib (or Mayavi)? Here is what I did so far:

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))

解决方案

Change to:

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

and call:

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

will create the following graph:

If you need the curve been filled with white color:

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()

这篇关于在3D Matplotlib情节脉冲传播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆