Skip to content

Commit 6c5e3f3

Browse files
authored
Merge pull request matplotlib#29520 from Anselmoo/Anselmoo/issue29519
FIX: Correct variable name from _frame to _frames in PillowWriter class
2 parents 3b329d9 + 0be53be commit 6c5e3f3

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/matplotlib/animation.py

+1-1
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

+18
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

@@ -526,3 +527,20 @@ def test_movie_writer_invalid_path(anim):
526527
with pytest.raises(FileNotFoundError, match=match_str):
527528
anim.save("/foo/bar/aardvark/thiscannotreallyexist.mp4",
528529
writer=animation.FFMpegFileWriter())
530+
531+
532+
def test_animation_with_transparency():
533+
"""Test animation exhaustion with transparency using PillowWriter directly"""
534+
fig, ax = plt.subplots()
535+
rect = plt.Rectangle((0, 0), 1, 1, color='red', alpha=0.5)
536+
ax.add_patch(rect)
537+
ax.set_xlim(0, 1)
538+
ax.set_ylim(0, 1)
539+
540+
writer = PillowWriter(fps=30)
541+
writer.setup(fig, 'unused.gif', dpi=100)
542+
writer.grab_frame(transparent=True)
543+
frame = writer._frames[-1]
544+
# Check that the alpha channel is not 255, so frame has transparency
545+
assert frame.getextrema()[3][0] < 255
546+
plt.close(fig)

0 commit comments

Comments
 (0)