matplotlib / matplotlib/matplotlib
Automated clip path generation should sometimes use intersection
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 23.2k
- 派生
- 8.5k
- 平均合并
- 1 天 6 小时
- 30 天内合并 PR
- 66
描述
In #23199 a change was introduced that does not overwrite the clip path if already set. There is one corner case that generates a new problem. Figure.add_artist(..., clip=True) used to clip based on "figure", but there is a (possibly artificial) case where it would be better to add an intersection of the figure and the set clip path. I guess that in general, it can be useful to have polygon intersection support, although it is a non-trivial case where we may want to rely on some external library. There are probably several issues that benefit from this, but at least #23454.
However, for this specific case, it may be a bit easier since we know that at least the figure is convex (a box) so it may be possible to solve it separately.
---
I think this is an example that shows that it is better to use the intersection:
```
import matplotlib as mpl
from matplotlib import pyplot as plt
fig, ax = plt.subplots()
poly3 = mpl.patches.Polygon([[-0.5, 0], [-0.5, 0.5], [0.5, 0.5], [0.5, 0]],
facecolor="g", edgecolor="y", linewidth=2, alpha=0.3)
fig.add_artist(poly3, clip=True)
line = mpl.lines.Line2D((-1, 1), (0.25, 0.25), color='r', clip_on=True, clip_path=poly3)
ax.add_artist(line)
# or
# fig.add_artist(line, clip=True)
```
With this PR one gets

while current master gives

or

_Originally posted by @oscargus in https://github.com/matplotlib/matplotlib/pull/23199#discussion_r1125638275_
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 issue 中的示例开始,检查由 #23199 更改的裁剪处理,尤其是 Figure.add_artist(..., clip=True) 所使用的路径。将现有的 figure 裁剪路径与显式设置的裁剪路径进行比较;完成的标准是渲染结果被裁剪为它们的交集,同时不改变不受影响的情况,并为此示例提供回归覆盖。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100