Inconsistent behavior for savefig.facecolor + savefig.transparent depending on output format · Issue #9921 · matplotlib/matplotlib · GitHub
Skip to content

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

Description

@anntzer

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:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions