I have a problem trying to capture an animation using a pygmt figure object and the Celluloid package (celluloid package website). When I try to put the normal celluloid code around a pygmt figure, it has trouble finding the figure axes:
---> 563 camera.snap()
564
~/anaconda3/envs/obspy/lib/python3.7/site-packages/celluloid.py in snap(self)
28 """Capture current state of the figure."""
29 frame_artists: List[Artist] = []
---> 30 for i, axis in enumerate(self._figure.axes):
31 if axis.legend_ is not None:
32 axis.add_artist(axis.legend_)
AttributeError: 'Figure' object has no attribute 'axes'
My figure does work normally without the celluloid package and I just initialize it in a normal way using:
fig = pygmt.Figure()
Does anyone have experience with how to extract the axes or does anyone have another easy way to animate a pygmt figure in a loop?
Hi @ktuin, thanks for trying out PyGMT! To answer you main question on creating an animation, you would want to use GMT’s movie function. Unfortunately that isn’t available for Python/PyGMT yet (although there’s been some talk about adding it). The celluloid package you linked above does look great, but it seems to be designed for matplotlib plots.
There are a few options you can try:
If you’re using Jupyter Lab/Notebook, you can try to access pure GMT commands like movie using an exclamation mark, e.g.
Hi @weiji14, thanks so much for your reply! Yes I indeed saw that celluloid doesn’t really work for images other than matplotlib. Thanks very much though for the movie function, I will check it out!