I am looking for a way to update my contour lines in an animation that does not require me to change my shape every time.
Most of the answers to this question I found a lawyer, recalling ax.contour, but since my contours overlap with another image, it is unbearably slow.
The only answer I found that is close to answering a question answers it with a dead link: Contour animation in matplotlib using FuncAnimation
Code example:
import matplotlib.pylab as plt
import matplotlib.animation as anim
from matplotlib.colors import LinearSegmentedColormap as lsc
import numpy
image_data = numpy.random.random((100,50,50))
contour_data = numpy.random.random((100,50,50))
def init():
global fig, ax, im, co
fig = plt.figure()
ax = plt.axes()
im = ax.imshow(image_data[0,:,:])
co = ax.contour(contour_data[0,:,:])
def func(n):
im.set_data(image_data[n,:,:])
co.set_array(contour_data[n,:,:])
init()
ani = anim.FuncAnimation(fig, func, frames=100)
plt.show()
Greetings.
source
share