Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[ENH]: Handling of closed streamlines in streamplot #27261

Copy link
Copy link
Open
@quenot

Description

@quenot
Issue body actions

Problem

With the current streamplot implementation, when asking for unbroken streamlines with given start points on fields with theoretically closed streamlines, the integration process spirals in practice until the maximum trajectory length is reached. The issue is more detailed, with an example and a workaround in this stack overflow question and answer. When it is theoretically known that some streamlines should loop over themselves, we would like to be able to specify it and integrate the streamlines so that they are actually closed or, at least, stop the integration when a "quasi-loop" has been detected, by passing again close enough to a start point and/or when a 360 degrees rotation has been observed for the velocity vector.

Proposed solution

A minimal and quite easy solution for single-direction integration could be to keep track of the accumulated rotation of the velocity vector along the trajectory, to continuously check the distance between the starting point and additional segments and to stop the integration at the closest point to the starting point after about one complete plus or minus 360 degrees velocity vector rotation and if the closest point is close enough to the starting point. Something similar though a bit more complicated could be done for two-direction integration.

A second-level solution would be to do exactly the same but while additionally modifying "on the fly" the original vector field with a very small rotation so that, after the integration, "the closest point to the starting point" becomes as close as possible to the starting point. The optimal "very small rotation" angle could be theoretically predicted and/or iteratively determined. Though this may appear as tampering with the source data, if there are good theoretical reasons to believe that the streamlines should be closed (the user should know what she or he is doing when using the "force_closed_streamlines" option), this is overall more likely to correct accumulated integration errors than to distort the result.

Having looked at the code, it seems to me that I should be able to implement this and maybe I will do so anyway for my personal use as the workaround that I am currently using is very impractical. However, it would certainly be done much better by matplotlib developers. Please let me know if this feature if of interest, if some matplotlib developers would consider implementing it, and if yes, how long it could take.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.