0

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

jdv
  • 13
  • 4
  • Probably related to https://github.com/matplotlib/matplotlib/issues/2517, – tacaswell Feb 18 '14 at 19:22
  • 1
    and can you add a bit more code so that there is a copy-pastable example to demonstrate this problem (use synthetic data). http://www.sscce.org/ Strongly suspect the work around is to do the mapping your self, adjust the alpha and then pass imshow the rgba arrays. – tacaswell Feb 18 '14 at 19:24

1 Answers1

0

To anyone suffering from this problem...

The solution was to update Matplotlib to the latest version. I was using the latest version of Matplotlib in the Ubuntu 12.04 repos, but I was multiple versions behind. The bug is resolved now. Thanks!

jdv
  • 13
  • 4