【发布时间】:2020-09-26 23:57:02
【问题描述】:
我有一些patches,我在matplotlib 中应用了不同的Affine2D 转换。
是否有可能将它们添加为collections.PatchCollection?不知何故,我只能为它们每个单独调用ax.add_patch() 才能绘制它们。
from matplotlib import pyplot as plt, patches, collections, transforms
fig, ax = plt.subplots()
trafo1 = transforms.Affine2D().translate(+0.3, -0.3).rotate_deg_around(0, 0, 45) + ax.transData
trafo2 = transforms.Affine2D().translate(+0.3, -0.3).rotate_deg_around(0, 0, 65) + ax.transData
rec1 = patches.Rectangle(xy=(0.1, 0.1), width=0.2, height=0.3, transform=trafo1, color='blue')
rec2 = patches.Rectangle(xy=(0.2, 0.2), width=0.3, height=0.2, transform=trafo2, color='green')
ax.add_collection(collections.PatchCollection([rec1, rec2], color='red', zorder=10))
# ax.add_patch(rec1)
# ax.add_patch(rec2)
【问题讨论】:
标签: python matplotlib affinetransform