2015-06-12 86 views
0

我有两个numpy大小的数组(Number_of_time_steps,N1,N2)。每一个代表的是Number_of_time_steps大小为N1xN2的平面中的速度,在我的情况下为12,000。这两个阵列来自两个流体动力学模拟,其中一个点在时间0处受到轻微扰动,并且我想研究由网格中每个点的速度扰动引起的差异。为此,在每个时间步骤中,我绘制了一个包含4个子图的绘图:平面1的pcolor图,平面2的pcolor图,平面之间的差异以及对数刻度中的平面之间的差异。我使用matplotlib.pyplot.pcolor创建每个子图。python中的交互式pcolor

这是可以很容易地完成的事情,但问题是,我最终会得到12,000个这样的图(保存为磁盘上的.png文件)。相反,我想要一种可以输入时间步的交互式绘图,它会将4个子图更新为相应的时间步,从两个现有数组中的值中更新。

如果有人对如何解决这个问题有任何想法,请高兴听到它。

回答

0

如果能够从ipython中运行,你可以只让一个函数来绘制你给出的时间步

%matplotlib # set the backend 
import matplotlib.pyplot as plt 

fig,((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, sharex='col', sharey='row') 

def make_plots(timestep): 
    # Clear the subplots 
    [ax.cla() for ax in [ax1,ax2,ax3,ax4]] 

    # Make your plots. Add whatever options you need 
    ax1.pcolor(array1[timestep]) 
    ax2.pcolor(array2[timestep]) 
    ax3.pcolor(array1[timestep]-array2[timestep]) 
    ax4.pcolor(array1[timestep]-array2[timestep]) 

    # Make axis labels, etc. 
    ax1.set_xlabel(...) # etc. 

    # Update the figure 
    fig.show() 

# Plot some timesteps like this 
make_plots(0)  # time 0 
# wait some time, then plot another 
make_plots(100) # time 100 
make_plots(12000) # time 12000