0
import matplotlib.pyplot as plt
import numpy as np

img1 = np.load('abc.npy')
img2 = np.load('xyz.npy')
fig, ax = plt.subplots()
ax.imshow(img1)
ax.imshow(img2, alpha = 0.1)

I want to merge two numpy arrays to a single image using matplotlib. This piece of code just shows the last image img2. How can I create a image where img1 and img2 are overlaid.

Arco Bast
  • 3,595
  • 2
  • 26
  • 53
Y.Millner
  • 41
  • 1
  • 6
  • This works as expected for me – Arco Bast Mar 23 '20 at 19:16
  • If the opacity is not set then you will not see the first images since the second is directly over it. Do you want to see these two images side-by-side [SO](https://stackoverflow.com/questions/21465988/python-equivalent-to-hold-on-in-matlab)? – lwileczek Mar 23 '20 at 19:16
  • Maybe one of the images is all white? Maybe one image is much larger than the other? – JohanC Mar 23 '20 at 20:15
  • Even if I set the alpha of both images to < 0.5, I can just see the image I call last. The numpy arrays have different size. I want to see them on top of each other integrated in one image. The image which is shown is the smaller one. – Y.Millner Mar 23 '20 at 20:20
  • A possible workaround: `ax.imshow(0.9*img1 + 0.1*img2)` (adjusting the ratio of `img1` to `img2` as needed). – Ken Mar 24 '20 at 01:36

0 Answers0