[英]Matplotlib patchcollection polygons do not touch
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:但是,当尝试用 PatchCollection 对 plot 它们进行处理时,两者之间似乎存在差距,它们并没有接触:
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()
Is there any reason for that in my code, and can I fix it?我的代码中是否有任何原因,我可以修复它吗? Thank you.谢谢你。
The issue may be backend-specific as I can't reproduce it.该问题可能是特定于后端的,因为我无法重现它。
However, you are not alone, as there is a long-standing open issue on matplotlib .但是,您并不孤单,因为matplotlib 上存在一个长期未解决的问题。
A suggested solution is to set the edge color, ie in your case:建议的解决方案是设置边缘颜色,即在您的情况下:
pc.set_edgecolor('face')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.