diff --git a/lib/matplotlib/backends/backend_agg.py b/lib/matplotlib/backends/backend_agg.py index c2caea38a043..cf9c54123050 100644 --- a/lib/matplotlib/backends/backend_agg.py +++ b/lib/matplotlib/backends/backend_agg.py @@ -584,12 +584,10 @@ def print_jpg(self, filename_or_obj, *args, dryrun=False, FigureCanvasAgg.draw(self) if dryrun: return - # The image is "pasted" onto a white background image to safely - # handle any transparency + # The image is pasted onto a white background image to handle + # transparency. image = Image.fromarray(np.asarray(self.buffer_rgba())) - rgba = mcolors.to_rgba(rcParams['savefig.facecolor']) - color = tuple([int(x * 255) for x in rgba[:3]]) - background = Image.new('RGB', image.size, color) + background = Image.new('RGB', image.size, "white") background.paste(image, image) if pil_kwargs is None: pil_kwargs = {} diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index d56e5d3d9eb4..00f742f66596 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -674,8 +674,7 @@ def test_jpeg_alpha(): plt.figimage(im) buff = io.BytesIO() - with rc_context({'savefig.facecolor': 'red'}): - plt.savefig(buff, transparent=True, format='jpg', dpi=300) + plt.savefig(buff, facecolor="red", format='jpg', dpi=300) buff.seek(0) image = Image.open(buff)