0

I have a dictionary titled "fig_dict" and a corresponding dictionary titled "axes_dict". Currently, if I want to plot a particular figure I can just call fig_dict['key_of_interest'].show(). I also have a list of the dictionary keys (both are the same) titled dict_keys.

I would like to cycle through all keys and plot them like this: https://www.timera-energy.com/content/uploads/2014/11/Fwd-Curve-Animation.gif , where each figure is flashed for a certain amount of time and the cycle is repeated.

In my head this looks like:

for current_key in dict_keys:
    fig_dict[current_key].animate()

All other stackoverflow questions I can find on this topic don't deal with pre-made figures and don't seem to work. Is there an easy way to do this?

MattM
  • 317
  • 4
  • 12
  • Could you provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) that generates a toy set of figures and your dictionaries for ppl to play with? – Diziet Asahi Jan 02 '18 at 20:58

1 Answers1

0

This is not going to work as each figure is a separate window and could be located in different places on the screen. It's much better to have a single figure and redraw the axis each animation loop (e.g. use interactive mode with plt.ion(), pause to redraw plt.pause(0.1) and clear the axis with ax.cla() like this).

If you need to use your current format, I'd suggest creating a series of images and then making a video/gif from these files, e.g.

for i, current_key in enumerate(dict_keys):
    fig_dict[current_key].savefig("out{:05}.png".format(i))

and then make a video or gif (e.g. ffmpeg, gifsicle, etc),

ffmpeg -i out_%05d.png test.avi

some care may be in needed as the order of dictionaries are undefined.

Ed Smith
  • 12,716
  • 2
  • 43
  • 55