Why is matplotlib.PatchCollection messing with color of the patches?

匿名 (未验证) 提交于 2019-12-03 02:30:02

问题:

I make a number of patches like so -

node.shape = RegularPolygon((node.posX, node.posY),                             6,                 radius = node.radius,                                     edgecolor = 'none',                                     facecolor = node.fillColor,                                     zorder = node.zorder)  node.brushShape = RegularPolygon((node.posX, node.posY),                             6,                 node.radius * 0.8,                 linewidth = 3,                                     edgecolor = (1,1,1),                                     facecolor = 'none',                                     zorder = node.zorder)

And originally I was just putting them straight onto my axis like this -

self.plotAxes.add_artist(node.shape) self.plotAxes.add_artist(node.brushShape)

That worked fine. But now I want to put them into a PatchCollection and put that PatchCollection onto the axis. However, when I do that, all of my shapes are just blue. I don't understand how just putting into a collection is changing the color somehow. Can anyone help me out on what I need to be doing to keep the color values that I input as the faceColor for the patches?

The new code is -

node.shape = RegularPolygon((node.posX, node.posY),                         6,             radius = node.radius,                                 edgecolor = 'none',                                 facecolor = node.fillColor,                                 zorder = node.zorder)  node.brushShape = RegularPolygon((node.posX, node.posY),                         6,             node.radius * 0.8,             linewidth = 3,                                 edgecolor = (1,1,1),                                 facecolor = 'none',                                 zorder = node.zorder)  self.patches.append(node.shape) self.patches.append(node.brushShape)   self.p = PatchCollection(self.patches)  self.plotAxes.add_collection(self.p) 

回答1:

self.p = PatchCollection(self.patches, match_original=True) 

By default patch collection over-rides the given color (doc) 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).



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!