Matplotlib - 2的数字插曲 - 1动画 [英] Matplotlib - 2 Figures in Subplot - 1 is Animation
问题描述
我有两个数字,我想在一个插曲绘制:
I have two figures that I would like to plot in a subplot:
fig = plt.figure()
ax1 = fig.add_subplot(1,2,1)
ax2 = fig.add_subplot(1,2,2)
假设AX1是要与加分的动画(散点图)进行填充。 AX2然后装仓这些点到一个meshgrid并显示密度。
Assume that ax1 is going to be populated with an animation which adds points ( a scatter plot). Ax2 then bins these points to a meshgrid and displays the density.
我可以显示插曲1动画,并在完成添加密度图像subplot2?
Can I display the animation in subplot 1, and on completion add the density image to subplot2?
推荐答案
这应该是可能的。请看看在例如。您还可以检查previous问题:
This should be possible. Please take a look at the example. You may also check the previous question:
<一个href=\"http://stackoverflow.com/questions/10896054/simple-animation-of-2d-coordinates-using-matplotlib-and-pyplot\">Simple 2D动画坐标使用matplotlib和pyplot
下面是一个样本实现。第二幅图是隐藏的,直到第一个停止呈现:
Below is a sample implementation. The second plot is hidden until the first stops rendering:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
def update_line(num, data, line, img):
line.set_data(data[...,:num])
if num == 24:
img.set_visible(True)
return line, img
fig1 = plt.figure()
data = np.random.rand(2, 25)
ax1=plt.subplot(211)
l, = plt.plot([], [], 'rx')
plt.xlim(0, 1)
plt.ylim(0, 1)
plt.xlabel('x')
plt.title('test')
ax2=plt.subplot(212)
nhist, xedges, yedges = np.histogram2d(data[0,:], data[1,:])
img = plt.imshow(nhist, aspect='auto', origin='lower')
img.set_visible(False)
line_ani = animation.FuncAnimation(fig1, update_line, 25,
fargs=(data, l, img),
interval=50, blit=True)
line_ani.repeat = False
plt.show()
这篇关于Matplotlib - 2的数字插曲 - 1动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!