matplotlib / matplotlib/matplotlib
PatchCollection edges incorrect when clip path is set
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 23.2k
- Forks
- 8.5k
- Merge médio
- 1d 6h
- PRs com merge (30d)
- 66
Descrição
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
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
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- data-visualization
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 45/100