matplotlib / matplotlib/matplotlib
PatchCollection edges incorrect when clip path is set
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 23.2k
- Forks
- 8.5k
- Ø Merge
- 1 T. 6 Std.
- Gemergte PRs (30 T.)
- 66
Beschreibung
### Bug report
**Bug summary**
Cartopy has a mostly-superfluous `GeoAxes.background_patch` which I'm trying to convert to the standard `Axes.patch`. By default, the `Axes.patch` is a `Rectangle`, which triggers a fast-path to set a clip box instead of a clip path. However, since most map boundaries are non-square, the full clip path code is used instead. When doing so, this causes some strange artifacts.
(Un)Fortunately, it can be reproduced with plain Matplotlib below.
**Code for reproduction**
```python
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from matplotlib.collections import PatchCollection
from matplotlib.path import Path
pth = Path([[0, 0], [1, 0], [1, 1], [0, 1], [0, 1]],
[1, 2, 2, 2, 79])
fig, ax = plt.subplots(2, 2, sharex=True, sharey=True)
ax[0, 0].set_xlim(-1, 2)
ax[0, 0].set_ylim(-1, 2)
for a in ax[0]:
collection = a.add_collection(
PatchCollection([mpatches.PathPatch(pth)],
facecolor='C0', edgecolor='k'))
collection.set_clip_path(
Path([[0, 0], [1, 0], [1, 1], [0, 1], [0, 1]]),
a.transAxes)
for a in ax[1]:
patch = a.add_patch(mpatches.PathPatch(pth, facecolor='C0', edgecolor='k'))
patch.set_clip_path(
Path([[0, 0], [1, 0], [1, 1], [0, 1], [0, 1]]),
a.transAxes)
ax[0, 0].set_ylabel('PatchCollection')
ax[1, 0].set_ylabel('PathPatch')
ax[1, 0].set_xlabel('Default clip box')
ax[1, 1].set_xlabel('Custom clip path')
plt.savefig('test.png')
```
**Actual outcome**
In the bottom row is a plain `PathPatch`, and the top row is a `PatchCollection` containing the same `PathPatch`. The left column shows the default clipping (to the clip box of the `Axes`). The right column uses a clip path of a manually-specified 0-1 rectangle in `Axes` space, so it should be equivalent.
But the horizontal edges are either doubled over or the wrong width in the top-right case.

**Expected outcome**
All path edges should look the same.
**Matplotlib version**
* Operating system: Fedora 30
* Matplotlib version: 3.1.3 and master, 9d00ca839e5faf10257095ad1e2bfb5296549d47
* Matplotlib backend (`print(matplotlib.get_backend())`): TkAgg (probably only the Agg bit is relevant)
* Python version: 3.6.9 / 3.6.3
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Start with PatchCollection.set_clip_path and compare its rendering path with the PathPatch case in the supplied reproduction. Run the example with the reported versions or a current checkout, then verify that the PatchCollection's clipped horizontal edges match the PathPatch edges and are not doubled or incorrectly sized.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- data-visualization
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100