如何在Python中在固定的2D背景上绘制3D曲线

时间:2013-06-22 21:20:57

标签: python

我想显示一个随时间移动的gussian函数。我写的下面的代码可以为我做。现在,我想在xy平面中修复2D背景,然后在其上移动此gussian函数(在2D绘图上叠加3D绘图)。有什么办法吗?谢谢你的帮助

import math
import numpy as np
import matplotlib.pyplot as plt
from pylab import *
from mpl_toolkits.mplot3d import Axes3D
import time

teta=45;              # direction
v=0.09                        # Speed
sigma_x=0.1;              
sigma_y=0.1;               
x_0=0;                        # Initial location (center) of gussian function
y_0=0; 
T=20

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
count=-1
for t in [i for i in range(T+1)]:
    Miu_x=x_0+v*t*cos(teta*pi/180);
    Miu_y=y_0+v*t*sin(teta*pi/180);
    L=[]
    x_1=[]
    y_1=[]
    count=count+1    
    time.sleep(0.5) 
    for x in [-4+0.1*i for i in range(80)]:
        for y in [-4+0.1*i for i in range(80)]:
            a_x=pow((x-Miu_x)/(1.4*sigma_x),2);
            a_y=pow((y-Miu_y)/(1.4*sigma_y),2);
            x_1.append(x)
            y_1.append(y)
            zz=(exp(-1*(a_x+a_y)))
            L.append(zz);
     ion()
     draw() # force a draw
     plot(x_1,y_1, L, zdir='z')

0 个答案:

没有答案