I'm generating overlaid plots using imshow
and printing them to a multipage pdf using matplotlib.backends.backend_pdf.PdfPages
. I'm setting the alpha of the background in the overlay to 0 using:
edge = np.ma.masked_where(edge == 0, edge)
cmap = plt.cm.winter
cmap.set_bad('g', 0)
And then overlaying it onto a background image with the following two imshow commands:
plt.imshow(back[:, :, mid], cmap=plt.cm.gray, interpolation='nearest')
plt.imshow(edge[:, :, mid], cmap=cmap, interpolation='nearest', alpha=0.5)
This produces an image that renders properly if I use matplotlib.pyplot.show()
, but not matplotlib.backends.backend_pdf.PdfPages.savefig()
. Specifically, the alpha information is ignored in the imshow
call, but not the cmap.set_bad
call, which renders properly.
Thanks, Joseph