matplotlib / matplotlib/matplotlib
LineCollection.contains (ab)uses pickradius<=0 as marker for "filled"
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 23.2k
- フォーク
- 8.5k
- 平均マージ
- 1日 6時間
- マージ済み PR(30日)
- 66
説明
### Bug report
**Bug summary**
When the pickradius of a LineCollection is set to a <=0 value, LineCollection.contains treats the polygon as "closed".
**Code for reproduction**
```python
from matplotlib import pyplot as plt
from matplotlib.collections import LineCollection
from matplotlib.backend_bases import MouseEvent
import numpy as np
fig, axs = plt.subplots(2)
for ax, pr in zip(axs, [0, 10]):
coll = LineCollection([[(0, 0), (1, 0), (0, 1)]])
ax.add_collection(coll)
ax.set(xlim=(-1, 2), ylim=(-1, 2))
coll.set_pickradius(pr)
for x in np.linspace(*ax.get_xlim())[1:-1]:
for y in np.linspace(*ax.get_ylim())[1:-1]:
x1, y1 = ax.transData.transform((x, y))
contained, _ = coll.contains(
MouseEvent("button_press_event", fig.canvas, x1, y1))
ax.plot(x, y, "o", c="g" if contained else "r", ms=1)
plt.show()
```
**Actual outcome**

Note how on the top LineCollection (using pickradius=0), all points "in" the closed polygon are considered "contained".
**Expected outcome**
Only points exactly on the LineCollection are contained for pickradius = 0, no points are contained for pickradius < 0 (consistently with Line2D).
---
The relevant code is in Line2D.contains:
```python
ind = _path.point_in_path_collection(
mouseevent.x, mouseevent.y, pickradius,
transform.frozen(), paths, self.get_transforms(),
offsets, transOffset, pickradius <= 0, # <--- this last argument is "filled"
self._offset_position)
```
**Matplotlib version**
* Operating system: linux
* Matplotlib version: master, likely since a long time ago
* Matplotlib backend (`print(matplotlib.get_backend())`): any
* Python version: 38
* Jupyter version (if applicable): no
* Other libraries: no
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
LineCollection.contains から始め、Line2D.contains との動作を比較します。特に、レポートに示されている _path.point_in_path_collection の呼び出しを確認してください。提供されている再現コードを pickradius の値 0、10、0 未満で実行し、それぞれの値について包含が記載された期待される動作と一致することを確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- data-visualization
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 48/100