matplotlib: is it possible to show multiple images on a single Axes?

Viewed 128

The title says it all. I want to have many images displayed on a single subplot, to make a sort of "stack of images effect" like in this picture:

enter image description here

So far I've done something like:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.transforms as mtransforms
from matplotlib.cbook import get_sample_data


fig, ax = plt.subplots()

with get_sample_data("grace_hopper.jpg") as file:
    arr_img = plt.imread(file)

# 
stack_transform = mtransforms.Affine2D(
    np.array(
        [[0.4, 0, 0],
         [0.3, 1, 0.],
         [0, 0, 1]], dtype=float
        )
    )

im1 = ax.imshow(arr_img, extent = [-0.5, 0.5, -0.5, 0.5])
trans_data1 = stack_transform + ax.transData
im1.set_transform(trans_data1)

im2 = ax.imshow(arr_img, extent = [-0.5, 0.5, -0.5, 0.5])
trans_data2 = stack_transform.translate(-0.2, 0) + ax.transData # Note the applied translation
im2.set_transform(trans_data2)

As you can see, only the last imshow is displayed. I've also tried to transform an AnnotationBbox introduced here, but it did not work either...

0 Answers
Related