Description
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, 9d00ca8
- Matplotlib backend (
print(matplotlib.get_backend())
): TkAgg (probably only the Agg bit is relevant) - Python version: 3.6.9 / 3.6.3