Skip to content

Inconsistent behavior for savefig.facecolor + savefig.transparent depending on output format #9921

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

Closed
anntzer opened this issue Dec 4, 2017 · 1 comment
Milestone

Comments

@anntzer
Copy link
Contributor

anntzer commented Dec 4, 2017

Bug report

Bug summary

Setting both savefig.facecolor and savefig.transparent behaves differently depending on whether the image is saved as jpeg or png.

Code for reproduction

modified from test_image.test_jpeg_alpha

from pylab import *
rcdefaults()

plt.figure(figsize=(1, 1), dpi=300)
# Create an image that is all black, with a gradient from 0-1 in
# the alpha channel from left to right.
im = np.zeros((300, 300, 4), dtype=float)
im[..., 3] = np.linspace(0.0, 1.0, 300)

plt.figimage(im)

with rc_context({'savefig.facecolor': 'red', 'savefig.transparent': True}):
    plt.savefig("/tmp/test.jpg")
    plt.savefig("/tmp/test.png")

Actual outcome

test.png
test

test.jpg
test

Expected outcome

Some consistent behavior across formats (the fact that jpeg cannot represent transparency should not prevent either both files to have a red background or both files not to have a red background).

I plan to deprecate savefig.facecolor/savefig.edgcolor/savefig.transparent anyways (see #9080, #9698); mostly just noting the issue in the meantime.

Matplotlib version

  • Operating system:
  • Matplotlib version: master and 2.1
  • Matplotlib backend (print(matplotlib.get_backend())):
  • Python version:
  • Jupyter version (if applicable):
  • Other libraries:
@QuLogic
Copy link
Member

QuLogic commented Jun 3, 2021

The test code produces a greyscale image in both cases now, probably due to #15239.

@QuLogic QuLogic closed this as completed Jun 3, 2021
@QuLogic QuLogic added this to the v3.2.0 milestone Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants