Skip to content

Saving a pdf, with a single image, grayscale colormap, and transparent background produces a black background #4260

@breedlun

Description

@breedlun

This issue appears to be similar to what eventually got resolved in #1894

If I save a pdf with a single image, grayscale colormap and a transparent background, the axes background does not remain transparent. It becomes a black background. If I deviate from any of those ingredients, then the background is transparent as specified.

Example:

import matplotlib.pyplot as plt
from numpy.random import rand

fig, ax = plt.subplots(nrows=3, ncols=1, sharex=True)

ax[0].imshow(rand(15,15), extent=[0, 2, 15, 0], \
            cmap=plt.cm.gray, aspect='auto', interpolation='Nearest')

ax[1].imshow(rand(15,15), extent=[0, 2, 15, 0], \
            cmap=plt.cm.rainbow, aspect='auto', interpolation='Nearest')

ax[2].imshow(rand(15,15), extent=[0, 2, 15, 0], \
            cmap=plt.cm.gray, aspect='auto', interpolation='Nearest')
ax[2].imshow(rand(15,15), extent=[4, 6, 15, 0], \
            cmap=plt.cm.gray, aspect='auto', interpolation='Nearest')

ax[-1].set_xlim([0, 8])
fig.savefig('transparent.pdf', format='PDF', transparent = True)
fig.savefig('opaque.pdf', format='PDF', transparent = False)
fig.savefig('transparent.png', format='PNG', transparent = True)

Here is 'transparent.pdf', with the black background on the first set of axes:
transparent-pdf

Here is 'opaque.pdf', which looks correct:
opaque-pdf

Here is 'transparent.png', which also looks correct:
transparent

In case it matters, I am on Mac OS X 10.8.5, Enthought Canopy Python 2.7.6, and Matplotlib 1.4.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions