Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Closed
Milestone
Description
Raised athttps://stackoverflow.com/questions/25089068/how-does-imshow-handle-the-alpha-channel-with-an-m-x-n-x-4-input by@mwaskom
import numpy as npimport matplotlib.pyplot as pltd = np.ones((100, 100, 4), dtype=np.uint8)*255d[:, :, 3] = np.linspace(0, 255, num=100)plt.imshow(d, interpolation='none')plt.show()
One might expect the image to be completely white (as semi-transparent white over white should still be white), but is instead gray in the middle due to pre-multiplying of the alpha (1, 1, 1, .5) -> (.5, .5, .5) which is then composited with the background as an opaque layer, hence the gray.
Previously (related) discussion: