【问题标题】:Interactive pcolor in pythonpython中的交互式pcolor
【发布时间】:2015-06-12 14:48:29
【问题描述】:

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

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

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

【问题讨论】:

    标签: python-2.7 matplotlib plot interactive


    【解决方案1】:

    对于交互式图形,您应该查看 Bokeh:

    http://docs.bokeh.org/en/latest/docs/quickstart.html

    您可以创建一个滑块来显示您想要查看的时间片。

    【讨论】:

    • 谢谢。我检查了它,虽然它在 pyplot 中没有 pcolor 的等价物,但它有可以使用的 figure.image,虽然似乎没有 pcolor 那么多的选项。
    【解决方案2】:

    如果您可以在 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
    

    【讨论】:

      猜你喜欢
      • 2019-10-27
      • 1970-01-01
      • 2015-08-20
      • 2018-07-27
      • 2020-05-27
      • 2017-06-08
      • 1970-01-01
      • 1970-01-01
      • 2018-09-09
      相关资源
      最近更新 更多