I've run into an issue with matplotlib. Using this information, I'm able to set both the colour and alpha value for the figure's face. However, matplotlib seems to insist on implicitly blending this with white before rendering the output.
For example, using the following:
import matplotlib.pyplot as plt
fig = plt.figure()
fig.set_facecolor('black')
fig.patch.set_alpha(0.3)
ax = fig.add_subplot(111, axis_bgcolor='black')
ax.plot([1, 2, 3], [1, 2, 3], color='white')
fig.savefig('test_fig.png', facecolor=fig.get_facecolor(), edgecolor='none')
the figure background pixels in test_fig.png
have an RGBA value of (178, 178, 178, 77)
, not the expected (0,0,0,77)
. I've tried with a wide variety of colours -- the final output, in all cases, seems to equivalent to the specified colour+alpha being alpha-blended with an opaque white, followed by alpha values being reset to the specified original value.
Why is this happening?
Is there some layer of colour that I'm missing that's still set to white, or is this a bug with matplotlib?
Looks like a bug to me. I've submitted a pull request to fix it; it is fixed in versions v1.3+ https://github.com/matplotlib/matplotlib/pull/1868