正如 @unutbu 和 @Martin Valgur 的评论所表明的那样,我认为身材匀称是正确的选择。这个问题可能与之前的问题有些多余,但这里有一个干净的代码片段,应该可以满足您的需要。
策略是首先创建各种形状(矩形)的并集,然后绘制并集。这样,您就可以将各种形状“展平”为一个形状,这样就不会在重叠区域中出现 alpha 问题。
import shapely.geometry as sg
import shapely.ops as so
import matplotlib.pyplot as plt
#constructing the first rect as a polygon
r1 = sg.Polygon([(0,0),(0,1),(1,1),(1,0),(0,0)])
#a shortcut for constructing a rectangular polygon
r2 = sg.box(0.5,0.5,1.5,1.5)
#cascaded union can work on a list of shapes
new_shape = so.cascaded_union([r1,r2])
#exterior coordinates split into two arrays, xs and ys
# which is how matplotlib will need for plotting
xs, ys = new_shape.exterior.xy
#plot it
fig, axs = plt.subplots()
axs.fill(xs, ys, alpha=0.5, fc='r', ec='none')
plt.show() #if not interactive