English 中文(简体)
Matplotlib: how to animate pcolormesh with high data set
原标题:Matplotlib: how to animate pcolormesh with large data set

我正在使用<代码>matplotlib.pyplot,对一些阵列数据进行校正。 数据的形式是密集地图,因此,我有一小数的x和 y地点,并且与这些地点有关。

困难在于,我无法简单地更新强度数据,因为x和 y地点也发生了变化。

例如,我可以像这项工作那样做一些事情,但首先需要一个超定的x和 y 格网,涵盖整个范围:

cax = ax.pcolormesh(x, y, G[:-1, :-1, 0],
                    vmin=-1, vmax=1, cmap= Blues )
fig.colorbar(cax)

def animate(i):
     cax.set_array(G[:-1, :-1, i].flatten())

这一工作已经完成,但我最后用相当庞大的强度阵列填充了大部分零。

我发现了一个例子:here,允许改变x和数值。 这里是经过修改的MWE:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig2 = plt.figure()

x = np.arange(-9, 10)
y = np.arange(-9, 10).reshape(-1, 1)
base = np.hypot(x, y)
ims = []
for add in np.arange(15):
    x = np.arange(-9+add, 10+add)
    y = np.arange(-9+add, 10+add)
    x, y = np.meshgrid(x, y)
    ims.append((plt.pcolormesh(x, y, base + add, norm=plt.Normalize(0, 30)),))

im_ani = animation.ArtistAnimation(fig2, ims, interval=50, repeat_delay=3000,
                                   blit=True)
plt.show()

这里的问题有两个方面。 首先,我有大约3 000个框架,因此名单<代码>ims不可管理。 第二,我如何能够获得数据,在框架之间加以澄清,而不是一劳永逸地显示每个框架? 也许有更好的办法?

博恩斯:使用激光器可以替代im。 I ve 曾使用Slider, 涉及这些类型的数据,但只是首先使用巨大的x和 y grid。

得到帮助! 如果我不使用适当的标签,则道歉。

问题回答

我可能在此误解这个问题,但在此使用似乎更为合适。

With blitting

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig, ax = plt.subplots()

x = np.arange(-9, 10)
y = np.arange(-9, 10).reshape(-1, 1)
base = np.hypot(x, y)

def animate(i):
    x = np.arange(-9+i, 10+i)
    y = np.arange(-9+i, 10+i)
    x, y = np.meshgrid(x, y)
    pc = ax.pcolormesh(x, y, base + i, norm=plt.Normalize(0, 30))
    return pc,

ax.axis([-9,30,-9,30])
im_ani = animation.FuncAnimation(fig, animate, frames=30, interval=50, 
                                 repeat_delay=3000, blit=True)
plt.show()

Without blitting

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig, ax = plt.subplots()

x = np.arange(-9, 10)
y = np.arange(-9, 10).reshape(-1, 1)
base = np.hypot(x, y)


store=[]
def animate(i):
    x = np.arange(-9+i, 10+i)
    y = np.arange(-9+i, 10+i)
    x, y = np.meshgrid(x, y)
    if store:
        store[0].remove()
        del store[0]
    pc = ax.pcolormesh(x, y, base + i, norm=plt.Normalize(0, 30))
    store.append(pc)


ax.axis([-9,30,-9,30])
im_ani = animation.FuncAnimation(fig, animate, frames=30, interval=50, 
                                 repeat_delay=3000)
plt.show()

Can you also show how to animate pcolormesh from top to bottom EG : I have heatmap generated and I wanted to slowly display the pcolormesh or delay the pcolormesh and gradually increase it





相关问题
images sliding continuously with <table> and jQuery

I m trying to write a little test page that circulates images through a window (see image). I have colored boxes inside a table (gray border), with each box being a element. <table id="boxes" ...

WPF 3d rotation animations

I have a few 3d rectangles on my screen that I want to pivot around the Y axis. I want to press down with the mouse, and rotate the 3d object to a max rotation, but when the user moves their mouse, ...

Disable Windows 7 touch animation in WPF

In Windows 7 when you touch the screen there is a short animation that occurs at the touch point. In my WPF app I want to display my own touch points, without showing the one supplied by Windows. ...

jQuery block moving

I wanna move a div block to the top, so I coded like this: CSS part: .movingPart{ margin-top:80px; } jQuery part: $(document).ready(function() { $( #btn ).click(function() { $( .movingPart )....

Direct 2D gnuplot PNG animation?

Can anyone please confirm that yes/no Gnuplot 4.5 (on CVS) can output 2D animated PNG files? I have numerous datasets but one line that I d like to show iteratively in 3 different places in my graph. ...

Visual State Manager VS Animations in WPF

There is a lot of talk about the simplicity of Visual States and the transitions between them in WPF/Silverlight. I have the need to generate animations dynamically at runtime, to animate the ...

Create a ImageIcon that is the mirror of another one

I ll like to know if there is a way to create a ImageIcon that is the mirror of another ImageIcon. Searching on Google, I found how to do it by using many AWT libraries. Is there a way to do it with ...

how to drag in the animation in iphone application?

Iphone application is using the static co-ordinates to reach at some points in the application,which is based on the button event. But what i want is when i drag the item than it should reach at some ...

热门标签