Animate a series of volumes as a GIFΒΆ

A convenient way to compare two flat maps (e.g., prediction performance or tuning weights) is to flip back and forth between them. This example shows how to make an animated gif in which each frame is a flatmap.

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

Create several pycortex Volumes

volumes = {'first': cortex.Volume.random(subject='S1', xfmname='fullhead', vmin=-2, vmax=2),
           'second': cortex.Volume.random(subject='S1', xfmname='fullhead', vmin=-2, vmax=2)}

Plot flat maps individually

_ = cortex.quickflat.make_figure(volumes['first'])
_ = cortex.quickflat.make_figure(volumes['second'])
_ =
  • plot make gif
  • plot make gif

Generate an animated gif that switches between frames every 1.5 seconds

filename = "./flatmap_comparison.gif"
cortex.quickflat.make_gif(filename, volumes, frame_duration=1.5)

Display gif inline in an IPython notebook

import io
from IPython.display import Image

stream = io.BytesIO()
cortex.quickflat.make_gif(stream, volumes, frame_duration=1.5)



<IPython.core.display.Image object>

Total running time of the script: ( 0 minutes 15.237 seconds)

Gallery generated by Sphinx-Gallery