Matplotlib patchcollection polygons do not touch

Question:

I have two polygons which are supposed to touch each other horizontally (no gap).
However, when trying to plot them with PatchCollection, there seem to be a gap between the two, they are not touching:

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.collections import PatchCollection
from matplotlib.patches import Polygon

fig, ax = plt.subplots()
points1 = [[ 0.,  0.],
           [10.,  0.],
           [10., 10.],
           [ 0.,  8.]]
points2 = [[10.,  0.],
           [10., 10.],
           [20., 10.],
           [18.,  0.]]
pc = PatchCollection([Polygon(points1), Polygon(points2)])
ax.add_collection(pc)
ax.autoscale_view()
plt.show()

enter image description here

Is there any reason for that in my code, and can I fix it?
Thank you.

Asked By: yvrob

||

Answers:

The issue may be backend-specific as I can’t reproduce it.

enter image description here

However, you are not alone, as there is a long-standing open issue on matplotlib.

A suggested solution is to set the edge color, i.e. in your case:

pc.set_edgecolor('face')
Answered By: Paul Brodersen
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.