Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 06c73f9

Browse filesBrowse files
authored
Merge pull request #29531 from meeseeksmachine/auto-backport-of-pr-29520-on-v3.10.x
Backport PR #29520 on branch v3.10.x (FIX: Correct variable name from _frame to _frames in PillowWriter class)
2 parents 90ae776 + 11df011 commit 06c73f9
Copy full SHA for 06c73f9

File tree

2 files changed

+19
-1
lines changed
Filter options

2 files changed

+19
-1
lines changed

‎lib/matplotlib/animation.py

Copy file name to clipboardExpand all lines: lib/matplotlib/animation.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ def grab_frame(self, **savefig_kwargs):
496496
"RGBA", self.frame_size, buf.getbuffer(), "raw", "RGBA", 0, 1)
497497
if im.getextrema()[3][0] < 255:
498498
# This frame has transparency, so we'll just add it as is.
499-
self._frame.append(im)
499+
self._frames.append(im)
500500
else:
501501
# Without transparency, we switch to RGB mode, which converts to P mode a
502502
# little better if needed (specifically, this helps with GIF output.)

‎lib/matplotlib/tests/test_animation.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_animation.py
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import matplotlib as mpl
1414
from matplotlib import pyplot as plt
1515
from matplotlib import animation
16+
from matplotlib.animation import PillowWriter
1617
from matplotlib.testing.decorators import check_figures_equal
1718

1819

@@ -551,3 +552,20 @@ def test_movie_writer_invalid_path(anim):
551552
with pytest.raises(FileNotFoundError, match=match_str):
552553
anim.save("/foo/bar/aardvark/thiscannotreallyexist.mp4",
553554
writer=animation.FFMpegFileWriter())
555+
556+
557+
def test_animation_with_transparency():
558+
"""Test animation exhaustion with transparency using PillowWriter directly"""
559+
fig, ax = plt.subplots()
560+
rect = plt.Rectangle((0, 0), 1, 1, color='red', alpha=0.5)
561+
ax.add_patch(rect)
562+
ax.set_xlim(0, 1)
563+
ax.set_ylim(0, 1)
564+
565+
writer = PillowWriter(fps=30)
566+
writer.setup(fig, 'unused.gif', dpi=100)
567+
writer.grab_frame(transparent=True)
568+
frame = writer._frames[-1]
569+
# Check that the alpha channel is not 255, so frame has transparency
570+
assert frame.getextrema()[3][0] < 255
571+
plt.close(fig)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.