Skip to content

proposed fix for transparency issue #27173 #27406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,11 @@ def func(current_frame: int, total_frames: int) -> Any

def _pre_composite_to_white(color):
r, g, b, a = mcolors.to_rgba(color)
return a * np.array([r, g, b]) + 1 - a
if type(writer) == PillowWriter:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be addressed

Suggested change
if type(writer) == PillowWriter:
if isinstance(writer, PillowWriter):

print("no true transparency using pillow")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print("no true transparency using pillow")

return a * np.array([r, g, b]) + 1 - a
else:
return np.array([r, g, b, a])

savefig_kwargs['facecolor'] = _pre_composite_to_white(facecolor)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the name of the internal function _pre_composite_to_white, I think it makes more sense to put the conditional around this bit of code (and just not call the function if we don't need it) rather than make the function actually do "maybe pre-composite with white based on the type of something in my outer scope".

savefig_kwargs['transparent'] = False # just to be safe!
Expand Down