Description
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.