0
##my code only plots the first image

import matplotlib.pyplot as plt

cm = plt.cm.RdBu_r

cm.set_under('white')

#this plots the first image

img1= plt.imshow(ing_frame,cmap=cm,vmin=12)

#this plots the second image

img2=plt.imshow(in_frame)

plt.show()

I need a way to combine both images with the white background

karlphillip
  • 92,053
  • 36
  • 243
  • 426
  • Hi. Is this related to your [other question](https://stackoverflow.com/questions/76618741/how-to-change-the-background-facecolor-theme-of-two-overlaid-images-plot-in-pyth)? If so, what are the value ranges of each image, also what is the background value in both cases? – Flow Jul 06 '23 at 08:32

1 Answers1

0

It's not entirely clear what is the effect you are looking for but it is possible to overlay two images using a predetermined alpha value with subplots on matplotlib:

import matplotlib.pyplot as plt
import numpy as np
from PIL import Image

cm = plt.cm.RdBu_r
cm.set_under('white')

# load both images
frame1 = np.asarray(Image.open('polarbear.png'))
frame2 = np.asarray(Image.open('dog.png'))

# overlay both images using an alpha
fig, ax = plt.subplots()
ax.imshow(frame1, cmap=cm, vmin=12, alpha=0.5)
ax.imshow(frame2, alpha=0.5)
ax.set_axis_off()

# display result
#plt.savefig('plot_output.png')
plt.show()

Output:

enter image description here

karlphillip
  • 92,053
  • 36
  • 243
  • 426
  • the thing I can not maintain the 'white' background as I am plotting two trajectories – user22178063 Jul 05 '23 at 20:58
  • @user22178063 one thing is to plot two **images** as stated in the original questio, and an entirely different thing is to plot two **trajectories** (or data points). A key part of getting the Stackoverflow community to help you is to be as precise and accurate as possible on the problem description. – karlphillip Jul 06 '23 at 15:58