Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
breedlun opened this issue Mar 22, 2015 · 3 comments

Comments

@breedlun
Copy link
Contributor

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

@tacaswell tacaswell added this to the next point release milestone Mar 22, 2015
@dkua
Copy link
Contributor

dkua commented Mar 23, 2015

Can confirm that this also occurs on

Mac OS X 10.9.5, Python 2.7.9, matplotlib 1.4.3
and
Ubuntu 12.04 LTS, Python 2.7.3, matplotlib 1.4.3

@jkseppan
Copy link
Member

I recently fixed one bug related to alpha channels in grayscale images, and I cannot reproduce this problem on current master, so I'll assume the fix helped with this case too. Thanks for a clearly written report, and please feel free to reopen if this reappears.

@breedlun
Copy link
Contributor Author

I can confirm the issue is gone now. Thanks to @jkseppan.

breedlun pushed a commit to breedlun/clearplot that referenced this issue Oct 20, 2020
…unction because scipy's imread is deprecated. Also eliminated the comment about matplotlib/matplotlib#4260 since it appears to be resolved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants