0

I overlaid two images and I used mutiple

#ways to change the theme into white

#none worked to do that

#plt.figure(facecolor='white')

#plt.style.use("seaborn-whitegrid")

#fig.set_facecolor('white')

#plt.gcf().set_facecolor('white')

#plt.figure()

#fig.patch.set_facecolor('white')

#3mpl.rcParams['figure.facecolor'] = 'white'

#None of the above worked to change the theme into white

#This is how I overlaid the images

import matplotlib.pyplot as plt

plt.imshow(in_frame,alpha=0.1)

plt.imshow(ing_frame,cmap='RdBu', alpha =0.5)

plt.show()

#see attached image

#Change the theme or background from blue into 'white'``

  • What do you mean by changing the theme to white? Do you want to get rid of grid and/or axis? Then [this](https://stackoverflow.com/questions/45148704/how-to-hide-axes-and-gridlines) might help you. Else you need to clarify what exactly you would like to become white. – Flow Jul 05 '23 at 12:16
  • @Flow change the background into white (theme_minimal). The background is blue in current image, so I need to change it to make the trajectories clearer – user22178063 Jul 05 '23 at 12:27
  • Sorry, I did not realize the area is bluish. Honestly I am wondering how this happens as these few lines of code result in a normally (that is not bluish) looking image. Are your images by chance causing this? Or is it an unwanted sideeffect of using the colormap `RdBu`? – Flow Jul 05 '23 at 12:48
  • @Flow yes,it is the unwanted sideeffect of using the colormap RdBu – user22178063 Jul 05 '23 at 12:55
  • 1
    Then itt might be possible to get rid of the background by thresholding your image(s) accordingly before showing them or by tweaking the optional parameters of `imshow`, `vmin` and `vmax`. – Flow Jul 05 '23 at 13:09
  • @Flow vmin & max did not work. The problem I need to plot the red and blue line with white background. – user22178063 Jul 06 '23 at 12:02
  • Since I do not know the details about your images I have to speculate: It might be that the chosen colormap is not well suited for your purpose. Maybe it would be better to use different colormaps for the images or to preprocess the images. What is the value range of both images, to which color(s) should these be mapped and what are the background values? – Flow Jul 06 '23 at 12:21

1 Answers1

0

I successfully reproduced your problem with two grayscale images of uniform background (values where 0) using the RdBu colormap. If you have a look at the colormap you see that white is used for intermediate values, while the background will be at the end of the value spectrum. Therefore I recommend using separate colormaps for the individual images as in the following example:

import matplotlib.pyplot as plt
from PIL import Image

in_frame = Image.open(r'D:\test\c1.png')
ing_frame = Image.open(r'D:\test\d1.png')

plt.imshow(in_frame, cmap='Reds', alpha=0.1)
plt.imshow(ing_frame, cmap='Blues', alpha =0.5)

plt.show()

That way I managed to get colored areas of one image in red, that of the other in blue and the background stayed white.

Flow
  • 551
  • 1
  • 3
  • 9