I want to plot multiple rectangle patches in one plot. I have read that it is much faster to add the patches all at once. The problem I am facing is that the color attribute is being ignored.The patches are drawn, however only in blue.
When I add the patches one at time, there is no problem. The color attribute is crucial must be defined when the patch is created.
patchCollections = []
For x in list:
rect = patches.Rectangle((x,y), 1, 1, color='{}'.format(x[1]))
patchCollections.append(rect)
ax.add_collection(PatchCollection(patchCollections))
CodePudding user response:
Solved
ax.add_collection(PatchCollection(patchCollections, match_original=True))
By default patch collection over-rides the given color for the purposes of being able to apply a color map, cycle colors, etc. This is a collection level feature (and what powers the code behind scatter plot)
match_original= True
must be added