I am trying to plot a collection of finite element data with colored patches used to represent the value in each element.
Unfortunately, when I plot the patches I get small gaps between adjacent patches.
I have created an example script below to describe the problem.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from matplotlib.collections import PatchCollection
nodes = [[0.1, 0.1],
[0.25, 0.1],
[0.75, 0.9],
[0.1, 0.9],
[0.9, 0.1],
[0.9, 0.9]]
elems =[[0,1, 2, 3],
[1, 4, 5, 2]]
patches = []
for elem in elems:
xy = np.array([nodes[i] for i in elem])
elem = mpatches.Polygon(xy, closed=True, snap=False, antialiased=True)
patches.append(elem)
col = PatchCollection(patches)
fig, ax = plt.subplots(1, 1)
ax.add_collection(col)
plt.show()
Which produces the following plot with the unwanted gap. Adjusting the shape of the plotting window changes the appearance of the gap.

At the moment my workaround is to set col.set_edgecolor("face")` and to include a small edge width. However, it's hard to set the edge to reduce artifacts when there is a range of different patch sizes.
Edit: as @tdy pointed out increasing the dpi when saving the figure helps reduce the gap, but doesn't eliminate it entirely. With an excessive dpi of 1000 the gap is only visible if you zoom in (click the image first) on a high res monitor.

For example for my real data with no edge width (edgecolor=None) there are lines separating each element.

Setting edgecolor="face" with linewidth=1.0 removes the lines between elements, but adds small artifacts at the corners of cells. This are particularly visible at the front of the geometry where the colors are very different and the elements are small.

Reducing the linewidth to 0.5 reduces the impact of these artifacts, but the lines between the larger elements in the middle start to reappear.

Is it possible to fix these gaps? I know this is a small thing, but I'd love to have a way to plot my data in python without artifacts.
I have tried setting snap=False and antialisased=True, but neither had any effect.


