Did anybody successfully create animations using a 3D (time and 2 spatial dimensions) xarray.Dataset ?
I am able to setup things manually, but I like how the xarray plotting routines set the titles correctly and don't want to rewrite that stuff.
With the help from
this I have this so far:
class UpdateQuad(object):
def __init__(self, ax, data):
self.data = data
self.quad = data[0].plot(vmax=72)
def init(self):
print('update init')
self.quad.set_array(np.asarray([]))
return self.quad
def __call__(self, i):
# data at time i
ti = self.data[i]
self.quad.set_array(ti.data.ravel())
return self.quad
fig, ax = plt.subplots()
ud = UpdateQuad(ax, fuv.data)
anim = animation.FuncAnimation(fig, ud, init_func=ud.init,
frames=10, blit=False)
anim.save('spectrograms.mp4')
For reasons that are unclear to me, I am not able to make this simply with an update function and on root scripting level.
Now the gripes: If I run it with this __call__() method, I get the right data into the
animation, but obviously the title is not being updated, as I only set the data array of the QuadMesh to the new data.
With this __call__() method:
def __call__(self, i):
# data at time i
ti = self.data[i]
self.ax.clear()
I should in principle get the data with the titles updated, but it seems that the ax.clear() does not remove the colorbar, so that I get a new colorbar each time, even so I return a QuadMesh object to the animator
(see here)
Would somebody have an idea how to solve this?
Cheers,
Michael