-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Transparency in Animations #5335
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
Comments
This is just a post to document an attempt and the difficulties I ran into. Good for me to reference when I try again, or perhaps useful if anyone else takes a peek. I tried to give (while crossing my fingers)
Get error: I think it has to do with Line 82 in c32bde5
Haven't figured a way around that yet. The goal is to then use numpy to flatten RGBA -> RGB to see if something like this would work for making the animations better by default. EDIT: This error has been fixed. I was referencing github src code for write_png (which wants 2 or 3 arguments) where matplotlib 1.4.3 wanted 5 arguments for width and height. I guess this has changed since. Note, whoever changed the error message to |
Could you try setting |
I got the same results with I used convert's +adjoin argument to deconstruct those frames from the gif and this is what they look like: It looks like imagemagick really wants to keep the alpha channel (as shown in the first gif), but is then forced to decide between full alpha or no alpha which is what gives the pixelated appearance, and then for the later frames I guess it gives up on the whole alpha channel idea for some reason unknown to me. |
Issue update: I have written some quick code as a possible solution, but I ran into issues with animations in my git-installed version of matplotlib. I will need to figure this out, but here is something I was considering:
This would add an |
Closing, as I don't see the issue with current nbagg and master matplotlib. OTOH, feel free to reopen if I'm in error. |
This report is somewhat of an extension to #5302. It seems easy to miss handle transparent regions while working with nbagg. The following is an example taken from the animation examples:
The output produced is:
As you can see, there is again some issues with the rendering of text in the figure (not axes) area where nbagg has set transparency to true. The im.mp4 file looks nearly identical to the gif.
I believe matplotlib saves each frame as a png and then sends those pngs to be saved as an animation through convert (imagemagick) or ffmpeg. I believe the issue here is that while gifs properly support transparency, they only support either full alpha or no alpha, which forces imagemagick to decide between alpha or no alpha for each intermediate alpha which gives a pixelated appearance.
If we insert the code [for some reason
with plt.rc_context({'nbagg.transparent': False})
doesn't work here]:Then we will get this:
Perhaps we can just disable transparency for gif files all together (I don't think matplotlib can properly handle boolean alpha levels), and then set the default frame format to gif files for animations;
animation.frame_format: 'gif'
The text was updated successfully, but these errors were encountered: