python 中的交互式 pcolor
Interactive pcolor in python
我有两个大小为 (Number_of_time_steps, N1, N2) 的 numpy 数组。每个代表 Number_of_time_steps 大小为 N1xN2 的平面中的速度,在我的例子中是 12,000。这两个阵列来自两个流体动力学模拟,其中一个点在时间 0 处受到轻微扰动,我想研究由网格中每个点的速度扰动引起的差异。为此,对于每个时间步长,我制作了一个包含 4 个子图的图:平面 1 的 pcolor 图、平面 2 的 pcolor 图、平面之间的差异以及对数比例下的平面差异。我使用 matplotlib.pyplot.pcolor 创建每个子图。
这是很容易完成的事情,但问题是我最终会得到 12,000 个这样的图(在磁盘上保存为 .png 文件)。相反,我想要一种交互式绘图,我可以在其中输入时间步长,它会将 4 个子图更新为两个现有数组中的值对应的时间步长。
如果有人对如何解决这个问题有任何想法,很高兴听到。
对于交互式图形,您应该查看 Bokeh:
http://docs.bokeh.org/en/latest/docs/quickstart.html
您可以创建一个滑块来调出您想要查看的时间片。
如果您可以 运行 从 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
我有两个大小为 (Number_of_time_steps, N1, N2) 的 numpy 数组。每个代表 Number_of_time_steps 大小为 N1xN2 的平面中的速度,在我的例子中是 12,000。这两个阵列来自两个流体动力学模拟,其中一个点在时间 0 处受到轻微扰动,我想研究由网格中每个点的速度扰动引起的差异。为此,对于每个时间步长,我制作了一个包含 4 个子图的图:平面 1 的 pcolor 图、平面 2 的 pcolor 图、平面之间的差异以及对数比例下的平面差异。我使用 matplotlib.pyplot.pcolor 创建每个子图。
这是很容易完成的事情,但问题是我最终会得到 12,000 个这样的图(在磁盘上保存为 .png 文件)。相反,我想要一种交互式绘图,我可以在其中输入时间步长,它会将 4 个子图更新为两个现有数组中的值对应的时间步长。
如果有人对如何解决这个问题有任何想法,很高兴听到。
对于交互式图形,您应该查看 Bokeh:
http://docs.bokeh.org/en/latest/docs/quickstart.html
您可以创建一个滑块来调出您想要查看的时间片。
如果您可以 运行 从 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