-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix gaps in streamplot's by changing capstyle #25078
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
Lengthen the tiny segments with changing their capstyle. This way, they appear as connected to each other.
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.
Thank you for opening your first PR into Matplotlib!
If you have not heard from us in a while, please feel free to ping @matplotlib/developers
or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.
You can also join us on gitter for real-time discussion.
For details on testing, writing docs, and our review process, please see the developer guide
We strive to be a welcoming and open project. Please follow our Code of Conduct.
Ideally, we'd figure out how to join all the segments; I don't know if that's possible with the multiple options-per-segment I mentioned in the issue, though. This change is causing all streamplot tests to fail because they were generated with the previous broken-per-segment setup. Those would need to be updated if this is the way to go. I think for uniform line width/colour, we do want to go with my suggestion at #24946 (comment); I'm not sure yet whether this capstyle change is what we want to do for the other cases; I think we'd need to look into the effect on the variable width/colour closely first. |
Thank you for the feedback. I will try to implement a non-hacky way to fix this. I looked up for a solution to implement a whole stream line with variable line width and variable color; however, I cannot seem to find a way to do this, as you mentioned in the issue, @QuLogic. Is implementing a solution that incorporates overlapping streamlines, or in other words, slightly longer streamlines, a reasonable solution for this issue? This is similar to having rounded caps but should be more proper. |
I think that for uniform color, uniform width lines, switching to drawing continious lines in the correct solution. For variably width / variable color I suspect the best "quick" fix is to make the stepsize smaller and the "right" fix is to upgrade the "lines" to effectively use pcolormesh as what we need is not rectangles, but quadrilaterals.... |
Altering the step sizes makes the produced images enormously large and generation of the plot considerably slow. That's why I thought it is out of the window. Though smaller step size could be a solution for smoother color gradients. @tacaswell, by using pcolormesh are you thinking of creating every small segment as a quadrilateral? Then, should the start and end points are separated by starting and ending line widths? Just to show the quick-fix with overlapping streamlines, below is how it ended up looking. It fixes the gaps appearing between the lines though the connection still expands discretely between the two line widths. |
I'm going to close this as it is clear that the consensus is that a different solution is likely to win out. @gokberkgunes thank you for your interest in fixing this, feel free to open an alternate PR with at least the proposed solution for the homogeneous width/color case. Note that that will still have test failures at the outset because the generated images are different (though better). The idea of using a QuadMesh to draw the segments is interesting, and may work, but has some particularly challenging considerations (in particular that linewidth is specified in screen coordinates (i.e. points) but the position is specified in data coordinates). |
Yes, which ends up being a fair bit of computational geometry (you need the slope of the segment on either side, average them, then get the normal) and to compute the line width (which is set in screen space). I suspect that the chain in the It does not seem impossible, just a fair bit of detailed work (and a new |
Lengthen the streamplot's tiny segments by changing their default cap style to rounded. This way, they appear connected to each other.
This commit fixes #24946.
PR Summary
PR Checklist
Documentation and Tests
pytest
passes)Release Notes
.. versionadded::
directive in the docstring and documented indoc/users/next_whats_new/
.. versionchanged::
directive in the docstring and documented indoc/api/next_api_changes/
next_whats_new/README.rst
ornext_api_changes/README.rst