matplotlib / matplotlib/matplotlib
[ENH]: Handling of closed streamlines in streamplot
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 23.2k
- 派生
- 8.5k
- 平均合并
- 1 天 6 小时
- 30 天内合并 PR
- 66
描述
### 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](https://stackoverflow.com/questions/77344931/how-can-i-avoid-spiraling-streamlines-in-matplotlib-pyplot-streamplot). 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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 streamplot 的实现以及链接的 Stack Overflow 示例和 workaround 开始。比较针对单向积分和双向积分所提出的处理方式,然后确定闭合轨迹或近似循环轨迹应如何停止;完成的标准是,闭合流线不再螺旋前进,直到达到最大轨迹长度。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- matplotlib, python
- 领域
- data-visualization
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 30/100