-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I tried adapting So the alpha channel is correct, but the line style is wrong. The result looks correct if I remove |
The proposed fix looks reasonable. |
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 |
No progress on the linestyle issue, maybe @anntzer can help? |
Looks like
should fix the dashes issue. Can you confirm? |
Can you just integrate it in your pr? |
Sure, I can do that |
Do you want me to add the test as well? Currently there seems to be no tests for the cairo backend... |
There's also no machinery for that, but sure, if you can figure it out how to make it work, go for it! |
Sure, a drawback of using check_figures_equal is of course that we assume the reference figure is correct. |
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. |
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.
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. |
Ah ok, should I change the patch then to remove draw_path_collection? |
At least I can't think of anything better... |
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 wrong assumptions in the grouped draw optimization. Add test for the cairo backend to check rendering of path collections. Fixes matplotlib#12773
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 to suggest an improvement. |
…v3.0.x Backport PR #12774 on branch v3.0.x
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.