Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
Consider alpha channel from RGBA color of text for SVG backend text opacity rendering#10773
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| ifcolor!='#000000': | ||
| style['fill']=color | ||
| ifgc.get_alpha()!=1.0: | ||
| ifgc.get_forced_alpha()andgc.get_alpha()!=1.0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I would just remove the check on gc.get_alpha() here and have a straight if else... no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I put that in because a similar check appears at line 421, and it sort of makes it clearer that alpha should only be set if explicitly told to do so. Should it be changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
OK so we don't want to write the opacity if not needed (reasonable). I think here the flow is clearer with
alpha = gc.get_alpha() if gc.get_forced_alpha() else gc.get_rgb()[3]if alpha != 1: style["opacity"] = short_float_fmt(alpha)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Yep, that's cleaner. 👍 Made the fix.
anntzer commentedMar 13, 2018
Nice, looks good modulo small fix. |
anntzer commentedMar 13, 2018
One last point: one issue we have in general with the mpl repo is the large size of test images, so we try to avoid adding too many images if possible. In this specific case, what takes a lot of room is the "path-as-text" svg. Can you merge the two svgs into a single one, and reduce the path-as-text part to a single character (to reduce the amount of embedded data)? You can always increase the amount of "text-as-text" if you want to keep the image self-explanatory. Once this is done, please squash out the earlier commits and force-push so that the large images don't stay in the repo. |
thuvejan commentedMar 13, 2018
So if I understand correctly, I should reduce the text labels in the svg that uses paths, to a single character because they take a lot space, but the text labels in the svg that uses text is fine because of it doesn't take a lot of space. Is this correct? Also, I wanted to put both figures into one svg, but I wasn't able to find a solution that allowed me to set different rcParams on two subplots of one figure. Do you know of any other way to make the two svg into one? |
anntzer commentedMar 13, 2018
Yes, your understanding is correct. |
b78ae5a tocd9d84fCompareanntzer commentedMar 13, 2018
Your email on the commit patch is marked as "thuvejan@users.noreply.github.com", it's up to you whether you want to put a real email there (either way let me know). |
thuvejan commentedMar 13, 2018
Yeah, that was intended 🙂 |
thuvejan commentedMar 13, 2018
@anntzer Thanks for all the feedback. Any idea when this will be merged? |
anntzer commentedMar 13, 2018
All PRs need two reviewers. |
PR Summary
This fix changes
_draw_text_as_pathand_draw_text_as_textinlib/matplotlib/backends/backend_svg.py, so that whencoloris supplied tomatplotlib.pyplot.textwith an RGBA value, the alpha channel is used. Previously, the alpha channel fromcolorwas being ignored. The changes added include extra conditions to checkGraphicsContextBase's_forced_alphavalue before setting text opacity based on theGraphicsContextBase's alpha value.Fixes#10419
People to notify:@anntzer@tacaswell@mdboom
PR Checklist