You can do this with Pillow:
from PIL import Image
im1 = Image.open("background.jpg")
im2 = Image.open("bird.jpg")
newimg = Image.blend(im1, im2, alpha=0.5)
newimg.save("blended.jpg")
I get this result:

python - Superimpose scatter plots - Stack Overflow
superimpose two protein by python script
superimpose an image over another image with python - Stack Overflow
Overlay two same sized images in Python - Stack Overflow
You simply call the scatter function twice, matplotlib will superimpose the two plots for you. You might want to specify a color, as the default for all scatter plots is blue. This is perhaps why you were only seeing one plot.
import numpy as np
import pylab as plt
X = np.linspace(0,5,100)
Y1 = X + 2*np.random.random(X.shape)
Y2 = X**2 + np.random.random(X.shape)
plt.scatter(X,Y1,color='k')
plt.scatter(X,Y2,color='g')
plt.show()

If you wish to continue using plot you can use the axis object returned by subplots:
import numpy as np
import pylab as plt
X = np.linspace(0,5,100)
Y1 = X + 2*np.random.random(X.shape)
Y2 = X**2 + np.random.random(X.shape)
fig, ax = plt.subplots()
ax.plot(X,Y1,'o')
ax.plot(X,Y2,'x')
plt.show()
Hello everyone
ı tried to superimpose two protein which ı have their pdb id .And ı need to print it as png.ı would like to do it py python script. I am not good at python. ı will be greatful for any help.
Thank you
Try using blend() instead of paste() - it seems paste() just replaces the original image with what you're pasting in.
try:
from PIL import Image
except ImportError:
import Image
background = Image.open("bg.png")
overlay = Image.open("ol.jpg")
background = background.convert("RGBA")
overlay = overlay.convert("RGBA")
new_img = Image.blend(background, overlay, 0.5)
new_img.save("new.png","PNG")
Maybe too old question, can be done with ease using opencv
cv2.addWeighted(img1, alpha, img2, beta, gamma)
#setting alpha=1, beta=1, gamma=0 gives direct overlay of two images
Documentation link
There might be better ways of applying a colorizing mask to an image, but if you want to do it the way you suggest, then this simple clipping will do what you want:
import numpy as np
image[:, :, 0] = np.clip(image[:, :, 0] + color_delta[0] * (mask[:, :, 0] / 255), 0, 255)
image[:, :, 1] = np.clip(image[:, :, 1] + color_delta[1] * (mask[:, :, 0] / 255), 0, 255)
image[:, :, 2] = np.clip(image[:, :, 2] + color_delta[2] * (mask[:, :, 0] / 255), 0, 255)
The result is:

Another way would be to simply modify the hue/saturation if your goal is to apply a color to a region. For instance:
mask = np.zeros((image.shape[0], image.shape[1]), dtype=np.bool)
mask[100:200, 100:500] = True
image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
image[mask, 0] = 80
image[mask, 1] = 255
image = cv2.cvtColor(image, cv2.COLOR_HSV2BGR)
One approach using np.clip & np.einsum -
import numpy as np
# Get clipped values after broadcasted summing of image and color_delta
clipvals = np.clip(image + color_delta,0,255)
# Mask of image elements to be changed
mask1 = mask[:,:,0]>0
# Extract clipped values for TRUE values in mask1, otherwise keep image
out = np.einsum('ijk,ij->ijk',clipvals,mask1) + np.einsum('ijk,ij->ijk',image,~mask1)
Runtime tests
In [282]: # Setup inputs
...: M = 1000; N = 1000
...: image = np.random.randint(-255,255,(M,N,3))
...: imagecp = image.copy()
...: mask = np.random.randint(0,10,(M,N,3))
...: color_delta = np.random.randint(-255,255,(3))
...:
In [283]: def clip_einsum(image,color_delta,mask):
...: clipvals = np.clip(imagecp + color_delta,0,255)
...: mask1 = mask[:,:,0]>0
...: return np.einsum('ijk,ij->ijk',clipvals,mask1) +
np.einsum('ijk,ij->ijk',image,~mask1)
...:
In [284]: def org_approach(image,color_delta,mask):
...: rows, cols = image.shape[:2]
...: #out = image.copy()
...: for row in range(rows):
...: for col in range(cols):
...: if mask[row, col, 0] > 0:
...: image[row, col, 0] = min(255, max(0,
image[row, col, 0] + color_delta[0]))
...: image[row, col, 1] = min(255, max(0,
image[row, col, 1] + color_delta[1]))
...: image[row, col, 2] = min(255, max(0,
image[row, col, 2] + color_delta[2]))
...:
In [285]: %timeit clip_einsum(image,color_delta,mask)
10 loops, best of 3: 147 ms per loop
In [286]: %timeit org_approach(image,color_delta,mask)
1 loops, best of 3: 5.95 s per loop