Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
Cairo backend: Fix alpha render of collections#12774
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
joh commentedNov 8, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I tried adapting So the alpha channel is correct, but the line style is wrong. The result looks correct if I remove |
anntzer commentedNov 8, 2018
The proposed fix looks reasonable. |
joh commentedNov 9, 2018
Had a look at the linestyles issue, and it seems to be unrelated to the grouped draw. It's incorrect also if I disable grouped draw, but correct if I remove |
joh commentedNov 9, 2018
No progress on the linestyle issue, maybe@anntzer can help? |
anntzer commentedNov 9, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Looks like should fix the dashes issue. Can you confirm? |
joh commentedNov 9, 2018
anntzer commentedNov 9, 2018
Can you just integrate it in your pr? |
joh commentedNov 9, 2018
Sure, I can do that |
joh commentedNov 9, 2018
Do you want me to add the test as well? Currently there seems to be no tests for the cairo backend... |
anntzer commentedNov 9, 2018
There's also no machinery for that, but sure, if you can figure it out how to make it work, go for it! |
joh commentedNov 9, 2018
Sure, a drawback of using check_figures_equal is of course that we assume the reference figure is correct. |
timhoffm commentedNov 9, 2018
You could e.g. compare an ellipse collection with two single ellipses. While in theory both may be wrong. On the one hand, it's reasonable to check that the two code paths yield the same result. Also it's quite unlikely that a future code change with simultaneously change both. So the test would actually be quite good. |
joh commentedNov 14, 2018
So I've added the test, which revealed yet another bug with the grouped draw (set_foreground() wasn't called for _rgb). After fixing this, the test passes, but only because it uses alpha blending and disables the grouped draw. Now if I modify the test and sett fill color alpha to 1.0, thus enabling grouped drawing, the draw order is messed up somehow: |
| edgecolor=(0, 0, 1, 0.75)) | ||
| ax.add_collection(col) | ||
| plt.savefig('patch_alpha_coloring_test.png') |
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.
no need to save the image in the test, you can check them using tools/triage_tests.py.
anntzer commentedNov 15, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Looking at this again I'm not surprised by the failure: this is because the pathcollection drawer concatenates all paths and fills them in one go, then draw the edges in one go (so the entire blue edge is drawn after the entire red fill). I overlooked the overlapping-patch problem in#8787, sorry about that. |
joh commentedNov 15, 2018
Ah ok, should I change the patch then to remove draw_path_collection? |
anntzer commentedNov 15, 2018
At least I can't think of anything better... |
anntzer commentedNov 19, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
The style checker is unhappy:https://travis-ci.org/matplotlib/matplotlib/jobs/456934939#L2255. The OSX test failure should be covered by#12835. |
Remove RendererCairo.draw_path_collection as it made some wrongassumptions in the grouped draw optimization.Add test for the cairo backend to check rendering of path collections.Fixesmatplotlib#12773
timhoffm commentedNov 28, 2018
Thanks and congratulations to your first contribution to matplotlib! Hope to see you back some time. |
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
And apply the correct labels and milestones. Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon! If these instruction are inaccurate, feel free tosuggest an improvement. |
…v3.0.xBackport PR#12774 on branch v3.0.x


Uh oh!
There was an error while loading.Please reload this page.
Fix for#12773
PR Summary
RendererCairo.draw_path_collection() had two issues related to alpha channels.
First, the call to gc.set_alpha in line 310 would also inadvertently set gc._forced_alpha = True. This is fixed by moving the line which updates the gc from gc_vars below the loop.
Second, the code has an optimization where artists with identical properties would be grouped and then rendered in one go. This strategy doesn't work if the artists overlap and have alpha value < 1.0 in which case alpha blending is necessary. So the second fix disables the grouping optimization if any of the artists have alpha < 1.0 or the whole collection has alpha < 1.0.
PR Checklist
Not yet, but I'll try to write one if necessary.