|
13 | 13 | import matplotlib as mpl |
14 | 14 | from matplotlib import pyplot as plt |
15 | 15 | from matplotlib import animation |
| 16 | +from matplotlib.animation import PillowWriter |
16 | 17 | from matplotlib.testing.decorators import check_figures_equal |
17 | 18 |
|
18 | 19 |
|
@@ -528,29 +529,18 @@ def test_movie_writer_invalid_path(anim): |
528 | 529 | writer=animation.FFMpegFileWriter()) |
529 | 530 |
|
530 | 531 |
|
531 | | -def test_exhausted_animation_with_transparency(tmp_path): |
| 532 | +def test_animation_with_transparency(): |
| 533 | + """Test animation exhaustion with transparency using PillowWriter directly""" |
532 | 534 | fig, ax = plt.subplots() |
533 | 535 | rect = plt.Rectangle((0, 0), 1, 1, color='red', alpha=0.5) |
534 | 536 | ax.add_patch(rect) |
535 | 537 | ax.set_xlim(0, 1) |
536 | 538 | ax.set_ylim(0, 1) |
537 | 539 |
|
538 | | - def update(frame): |
539 | | - # Modify transparency in each frame |
540 | | - rect.set_alpha(0.1 + frame * 0.1) |
541 | | - return [rect] |
542 | | - |
543 | | - # Create and save animation |
544 | | - anim = animation.FuncAnimation( |
545 | | - fig, update, frames=iter(range(5)), repeat=False, |
546 | | - cache_frame_data=False, |
547 | | - |
548 | | - ) |
549 | | - tmp_file = tmp_path / "test_transparent.gif" |
550 | | - anim.save(tmp_file, writer='pillow', savefig_kwargs={"transparent": True}) |
551 | | - |
552 | | - # Verify exhausted warning |
553 | | - with pytest.warns(UserWarning, match="exhausted"): |
554 | | - anim._start() |
555 | | - |
| 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 |
556 | 546 | plt.close(fig) |
0 commit comments