Gramian Angular FieldΒΆ

A Gramian Angular Field is an image obtained from a time series, representing some temporal correlation between each time point. Two methods are available: Gramian Angular Summation Field and Gramian Angular Difference Field. This example illustrates the transformation on the first sample of the GunPoint dataset. Both images are plotted side by side to illustrate the differences. It is implemented as pyts.image.GramianAngularField.

# Author: Johann Faouzi <>
# License: BSD-3-Clause

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import ImageGrid
from pyts.image import GramianAngularField
from pyts.datasets import load_gunpoint

# Parameters
X, _, _, _ = load_gunpoint(return_X_y=True)

# Transform the time series into Gramian Angular Fields
gasf = GramianAngularField(image_size=24, method='summation')
X_gasf = gasf.fit_transform(X)
gadf = GramianAngularField(image_size=24, method='difference')
X_gadf = gadf.fit_transform(X)

# Show the images for the first time series
fig = plt.figure(figsize=(8, 4))
grid = ImageGrid(fig, 111,
                 nrows_ncols=(1, 2),
images = [X_gasf[0], X_gadf[0]]
titles = ['Summation', 'Difference']
for image, title, ax in zip(images, titles, grid):
    im = ax.imshow(image, cmap='rainbow', origin='lower')
    ax.set_title(title, fontdict={'fontsize': 12})
plt.suptitle('Gramian Angular Fields', y=0.98, fontsize=16)

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

Gallery generated by Sphinx-Gallery